a question about __init__.py behavior in python 3.5.2. I noticed that "sys.argv" and "import __main__" behave differently depending on when they were called. For instance:
$ tree
└── subdir
├── __init__.py : "import sys; print(sys.argv)"
├── __main__.py : "import sys; print(sys.argv)"
$ python -m subdir
['-m']
['/path/to/code/subdir/__main__.py']
Here I am taken by surprise, as I would expect sys.argv to be the same throughout the life of the processes. I have an intuition as to why this is happening, but I am wondering if there is a way to find out the import time that the true sys.argv is in the __init__.py module.
For reference, it looks like argv is changed in lib / runpy.py @ _run_module_as_main
source
share