[New-bugs-announce] [issue14208] No way to recover original argv with python -m

Ben Darnell report at bugs.python.org
Tue Mar 6 07:53:23 CET 2012

New submission from Ben Darnell <ben.darnell at gmail.com>:

I have a script which attempts to re-invoke itself using sys.argv, but it fails when run with "python -m package.module".  The problem is that the handling of -m (via the runpy module) rewrites sys.argv as if it were run as "python package/module.py", but the two command lines are not equivalent:  With -m the current directory is inserted at the head of sys.path, but without -m it's the directory containing module.py.  The net effect is that the initial run of "python -m package.module" works as expected, but when it re-runs itself as "python package/module.py" the imports from module.py are effectively relative instead of absolute.

One possible solution would be to provide an immutable sys.__argv__ (by analogy with sys.__stdout__ and friends).

messages: 155002
nosy: Ben.Darnell
priority: normal
severity: normal
status: open
title: No way to recover original argv with python -m
type: enhancement

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list