import doesn't work as i want
fredrik at pythonware.com
Mon Jan 31 17:05:54 CET 2005
Olivier Noblanc wrote:
> In the botom of this post you will see my source code.
> The problem is when i launch main.py that doesn't make anything why ?
the "if __name__" statement checks the name of the module. if you run
Python file as a script, by passing a filename to the python interpreter, the
__name__ variable is set to "__main__". if you import a file as a module,
the __name__ is the name of the module, not "__main__".
if you want main.py to do something, move that code to main.py (or move
it into a function, and call it from main.py)
More information about the Python-list