Thanks Richard,

In fact, I should add more than the python executable in prog: it must
contain -m and the package « classpath », but I can try arpund this. I'll
come back with the results asap.

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.

Best regards.

Le sam. 24 août 2019 03:24, Richard Musil <[email protected]> a écrit :

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

Reply via email to