On Sat, Aug 24, 2019 at 9:25 AM Michael Hooreman <mich...@hooreman.be>
wrote:

> Running __main.py__ as a script works *only* if we use absolute imports.
> And I consider that using absolute imports in a package to itself is a very
> bad practice. So, __main.py__ is not an executable.
>

I probably should clarify my original statement. I did not mean that
`__main__.py` in a package should be directly executable. What I meant was
that someone can write a standalone script and being completely oblivious
of its special meaning of the name in the package hierarchy choose to name
it `__main__.py`. In this particular case it would be correct to expect
that ArgumentParser shows the name of the scripts as `__main__.py`.

It is not really a use case and I only gave it as an example that from the
ArgumentParser's perspective no special treatment can be derived based on
the name alone. Adding more complex logic to ArgumentParser to figure out
if it runs "inside the package" seems like an overkill, if it could be
resolved in the client code which already has most of the knowledge (that
it runs in `__main__.py` and in particular in `__main__.py` which has a
special role in the package).

Richard

>
_______________________________________________
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/5A4Q3X5RZS3XPSNHFJBX6JERAJHSJJG3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to