[Tutor] Question about __name__ global variable (Was: Tutor Digest, Vol 35, Issue 27)

wesley chun wescpy at gmail.com
Wed Jan 10 06:55:20 CET 2007


> The global variable __name__ is equal to '__main__' when the python
> script is run.
> If the script is imported, __name__ is something other than '__main__'
> (not sure what.)


it will be the name of your module.  so for foo.py, if you execute it
(as a script), __name__ == '__main__', but if you 'import foo',
__name__ == 'foo'.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list