[Python-Dev] Running a module as a script

Nick Coghlan ncoghlan at email.com
Fri Oct 1 06:47:15 CEST 2004


Quoting Nick Coghlan <ncoghlan at email.com>:
> - run the located script as __main__ (note that containing packages are NOT
> imported first - it's as if the relevant module was executed directly from
> the
> command line)

I've realised that this means that the '-m' option doesn't understand packages
that modify __path__ in their __init__.py scripts.

What do people think of semantics which say "python -m some.package.module"
means that "some.package" gets imported before "module" gets executed as "__main__"?

The advantages are that __path__ will be interpreted correctly and package
initialisation code will be invoked before the module is executed.

It seems slightly odd to be importing things before the script starts executing,
but these semantics seem to be more in line with the behaviour of the rest of
Python's import machinery.

Cheers,
Nick.


-- 
Nick Coghlan
Brisbane, Australia


More information about the Python-Dev mailing list