Message314350
Two of your 3 suggested alternatives could lead to bugs. To use your example:
python -m mainmodule.submodule.foobar -o -b
is a convenient alternative and abbreviation for
python .../somedir/mainmodule/submodule/foobar.py -o -b
The two invocations should give equivalent results and to the extent possible the same result.
[What might be different is the form of argv[0]. In the first case, argv[0] will be the "preferred" form of the path to the python file while in the second, it will be whatever is given. On Windows, the difference might look like 'F:\\Python\\a\\tem2.py' versus 'f:/python/a/tem2.py']
Unless __init__.py does some evil monkeypatching, it cannot affect the main module unless imported directly or indirectly. So its behavior should be the same whether imported before or after execution of the main module. This means that argv must be the same either way (except for argv[0]). So argv[0:2] must be condensed to one arg before executing __init__. I don't see that '' is an improvement over '-m'.
Command line arguments are intended for the invoked command. An __init__.py file is never the command unless invoked by its full path: "python somepath/__init__.py". In such a case, sys.argv access should be within a "__name__ == '__main__':" clause or a function called therein. |
|
Date |
User |
Action |
Args |
2018-03-24 01:15:22 | terry.reedy | set | recipients:
+ terry.reedy, ncoghlan, docs@python, Jonathan Huot |
2018-03-24 01:15:22 | terry.reedy | set | messageid: <1521854122.05.0.467229070634.issue33119@psf.upfronthosting.co.za> |
2018-03-24 01:15:21 | terry.reedy | link | issue33119 messages |
2018-03-24 01:15:19 | terry.reedy | create | |
|