Retrieving the full command line

Tim Golden mail at timgolden.me.uk
Tue Jan 22 10:24:23 CET 2013


[Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific,
though].

I use the python -mpackage incantation to run a package which has a
__main__.py module and which uses relative imports internally.

I'm developing under cherrypy which includes a reloader for development.
The reloader attempts to rebuild the original
command line by combining sys.executable and sys.argv and then does an
execv.

There does not appear to be any way within Python of determining the
command line I used. The combination of sys.executable and sys.argv in
this case will look like: "c:\python33\python.exe app/__main__.py". But
running this precludes the use of package-relative imports.

I can pull the command line out of the Windows API to solve this
specific problem, but is there not a gap here? Even if sys.flags somehow
indicated the -m (it doesn't) that wouldn't give me the filepath which
it used.

Have I missed something?

TJG



More information about the Python-list mailing list