Print function not working

MRAB python at mrabarnett.plus.com
Thu Aug 11 13:36:43 EDT 2016


On 2016-08-11 18:18, Chris Angelico wrote:
> On Fri, Aug 12, 2016 at 3:03 AM, Atri Mahapatra
> <atri.mahapatra at gmail.com> wrote:
>> I have installed IDLE 3.5.1 and wrote the following  to check if print is working. When it runs, I do not see anything is printed:
>>
>> class Base: #{
>>     def __init__( self ): #{
>>         print("Hello, world: \n\n");
>>
>>         #}
>>
>>     #}
>>
>>
>> if ( __name__ == " __main__"): #{
>>     root = Base();
>> #}
>>
>> Can anyone please point out the reason?
>>
>> Thanks,
>> Atri
>
> Is name equal to main? That is, are you running this code as a top-level script?
>
It's not checking whether the name is "__main__", but whether it's " 
__main__" (note the space after the first quote).

> Also: You do not need to write Python code as if it were C or Java.
> All that extra punctuation is just putting unnecessary stress on the
> world's punctuation mines, which are already overworked. :)
>
+1




More information about the Python-list mailing list