On Fri, Aug 23, 2019 at 11:54 PM Michael Hooreman <[email protected]>
wrote:

> The issue is with package foobar containing __main__.py file (not with a
> module called as a script, which is your case), and called via python -m
> foobar
>
> See the last paragraph of https://docs.python.org/3/library/__main__.html
> :
>

I have misread your original explanation. I can see it now. Now, another
(possibly again naïve) idea :)
Could you get the package name simply by parsing the path of the script? I
guess it will only work if the package is normally stored in the filesystem.

For example, since you already know that you are in `__main__.py` and this
file is a part of some package:

    prog = os.path.basename(os.path.dirname(os.path.abspath(sys.argv[0])))
    ap = ArgumentParser(prog=prog, description='Test default prog name')

The thing which I see arguable is that ArgumentParser is technically
correct when it shows `__main__.py` as an executed program/script and the
fact that this particular file has a special role in the package hierarchy
has no relevance for ArgumentParser operation. In other words, it is also
possible to execute a script called `__main__.py` without any package.

Richard

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

Reply via email to