if __name__=='__main__': main()
Andrew Henshaw
andrew.henshaw at gtri.gatech.edu
Sat Dec 21 22:51:40 EST 2002
Peter Hansen wrote:
> Andrew Henshaw wrote:
>>
>> jaime suarez wrote:
>>
>> > I am trying to run a script from IDLE and
>> > I get an error message saying
>> >
>> > main()
>> > ^
>> > SyntaxError: invalid syntax
>> >
>> Does your code look something like this?
>>
>> if __name__ == '__main__':
>> main()
>>
>> def main():
>> print 'spam'
>>
>> If so, then you will need to move the definition before its use, like so:
>
> This would lead to a NameError, not a SyntaxError, so it's unfortunately
> not likely the cause, valid though your advice is.
>
Very nicely put, thank you. It's amazing how easy it is to to overlook
facts when you're "sure" of the answer.
Thanks again,
Andy
More information about the Python-list
mailing list