Python's equivalent to Main calling program and subprograms

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Dec 1 12:20:01 EST 2010


m b wrote:
>
>
> > >
> > > if __name__ == "__main__":
> > > main()
>
> What does this mean?
>
> /Mikael
__name__ is an attribute of the module. Usually it is set to the module 
name, except when the module is acutally executed as the entry point, in 
that case __name__ is set to '__main__'.

foo.py:
print __name__


 > python foo.py
'__main__'

 > python -c "import foo"
'foo'

This is a very basic concept, you should read the python tutorial.

JM




More information about the Python-list mailing list