The original command python line

Damjan Georgievski gdamjan at gmail.com
Sun Mar 4 06:38:44 CET 2012


How can I get the *really* original command line that started my python
interpreter?

Werkzeug has a WSGI server which reloads itself when files are changed
on disk. It uses `args = [sys.executable] + sys.argv` to kind of
recreate the command line, and the uses subprocess.call to run that
command line.

BUT that's problematic as, when you run::

	python -m mypackage --config

sys.argv printed in mypackage/__main__.py will be::

	['/full/path/to/mypackage/__main__.py', '--config']

so you get::

	python /full/path/to/mypackage/__main__.py --config

instead of::

	python -m mypackage --config


the difference in the 2 cases is what the current package is, and
whether you can use relative imports.


-- 
damjan



More information about the Python-list mailing list