On Fri, Jan 10, 2020 at 11:53:10PM -0300, Soni L. wrote:
> currently python -m requires you to cwd to the desired package root. I'd
> like to suggest the ability to python -m
> relative/path/to/package/root/module.submodule and python -m
> /absolute/path/to/package/root/module.submodule
What do you mean?
`python -m` ought to run any module in the path, regardless of
whether it is a .py file or a package. (Or for that matter, a .pyc
file.) If `import spam.eggs` will find it, `python -m spam.eggs` ought
to run it. If it doesn't, that's a bug.
The only tricky thing is that to run a top level package, you need
`__main__.py` as the entry point, not `__init__.py`.
But running submodules of a package should just work. To test it, I
creates a package "spam" on the PYTHONPATH:
spam
+-- __init__.py
+-- __main__.py
+-- eggs.py
where `__init__.py` is an empty file, and the other two contain:
if __name__ == '__main__':
import __main__
print(__main__.__file__)
the cd'ed to a location off the PYTHONPATH, and ran these:
[steve@ando tmp]$ python3.5 -m spam.eggs
/home/steve/python/spam/eggs.py
[steve@ando tmp]$ python3.5 -m spam
/home/steve/python/spam/__main__.py
Have I misunderstood what you are trying to describe?
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/4F6X3JK4YFBPHIBEPQOP6E743WNDAWE2/
Code of Conduct: http://python.org/psf/codeofconduct/