Newbie trying to understand __name__=='__main__'

Erik Max Francis max at alcyone.com
Mon Sep 18 20:57:44 CEST 2000


Luc Lefebvre wrote:

> class Set:
	...
>     if __name__=='__main__':
>         print "running as \'main\'"
>         print "doesn't seem to want to run code below..."
>         x=Set([1,2,3,4])
	...

Remember, Python is sensitive to indentation.  You don't want this
fragment indented.  It should instead read:

    class Set:
        ...

    if __name__ == '__main__': # same indentation level as class Set
        ...

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Never make a promise or plan / Take a little love where you can
\__/ Florence, _Chess_
    Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
 A new, virtual planet, every day.



More information about the Python-list mailing list