import foo vs. python -m foo

Hrvoje Niksic hniksic at xemacs.org
Tue Oct 28 16:35:22 EDT 2008


Simon Bierbaum <bierbaum at vierfalt.com> writes:

> Hi all,
>
> what is the difference between saying "import foo" in an interactive
> prompt and starting one using "python -m foo"? The -m switch is not
> covered in the man page, is it even officially supported?

My copy of the man page states:

-m module-name
    Searches sys.path for the named module and runs the corresponding
    .py file as a script.

> I'm asking because one of my modules fails on import in the second
> version but succeeds in the first.

It probably contains buggy code inside "if __name__ == '__main__': ...".



More information about the Python-list mailing list