On 2020-01-11 9:01 p.m., Steven D'Aprano wrote:
On Sat, Jan 11, 2020 at 02:46:14PM -0300, Soni L. wrote:

> 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.

That's what you said in your first post. In my first response, I said it
works for me. Unless I have misunderstood you, I think you are mistaken
about needing to cd into the package root.

Can you give a clear (and simple) example of a package in the PYTHONPATH
where python -m package.module doesn't work?


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

If you know the precise location of the module, and you don't want to
search the PYTHONPATH, why are you using -m?

`python -m module` is for searching the PYTHONPATH when you don't know
or care precisely where module is located. Think of it as a hammer.

`python filename` is for running the module when you do know and care
precisely which file you are running. Think of it as a screwdriver.

You seem to be asking to weld a screwdriver head to a hammer so that you
can have the hammer behave like a screwdriver. If you know the precise
path you want to run, why are you using

     # your proposed syntax
     python -m spam/eggs/cheese.aardvark

when you could just as easily run this and get the effect you want?

     python spam/eggs/cheese/aardvark.py

This is not a rhetorical question. As far as I can tell from your
explanation so far, what you want to do is possible *right now* if you
just stop typing `-m` after the `python` command and use the right tool
for the job.

If you see a difference that I don't, please explain what that
difference is.



but those are *not* equivalent. the first one has spam/eggs/ as the package root, with cheese.aardvark as the module (the thing passed to "import" (except with the __main__ hacks that I don't wanna go into)). the second one has spam/eggs/cheese/ as the package root, and "aardvark" isn't even loaded as a module! if you did "import cheese.aardvark" it'd fail, and if you did "import .aardvark" it would load the module twice, once under "__main__" and once under "aardvark".
_______________________________________________
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/CJGICX2LCK5GIJLUMDIUAAAIFYCBPGXN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to