I just want python foo/bar/baz/qux/__main__.py but with imports that actually work. -m works, but requires you to cd. -m with path would be an more than huge improvement.

and it absolutely should look for the given module in the given path. not "anywhere in the PYTHONPATH".

On 2020-01-11 2:21 p.m., Steven D'Aprano wrote:
On Sat, Jan 11, 2020 at 11:27:51AM -0300, Soni L. wrote:

> PYTHONPATH=foo/bar python -m baz.qux
> > becomes > > python -m foo/bar/baz.qux > > which is less of a kludge.
Sorry Soni, I completely disagree with you.

The status quo `PYTHONPATH=foo/bar python -m baz.qux` is explicit about
changing the PYTHONPATH and it uses a common, standard shell feature.
This takes two well-designed components that work well, and can be
understood in isolation, and plugging them together. The first part of
the command explicitly sets the PYTHONPATH, the second part of the
command searches the PYTHONPATH for the named module.

Far from being a kludge, I think this is elegant, effective design.

It seems to me that your proposed syntax is the kludge: it mixes
pathnames and module identifiers into a complex, potentially
ambiguous "half path, half module spec" hybrid:

     foo/bar/baz.qux
     * foo/bar/ is a pathname
     * baz.qux is a fully-qualified module identifier, not a file name

The reader has to read that and remember that even though it looks
exactly like a pathname, it isn't, it does not refer to the file
"baz.qux" in directory "foo/bar/". It means:

* temporarily add "foo/bar/" to the PYTHONPATH
* find package "baz" (which could be anywhere in the PYTHONPATH)
* run the module baz.qux (which might not be qux.py)


_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/L7RRKAML6GWYXN4ULLD3U2ZOLS6CC4HM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to