Altering sys.argv on startup in Python 2

Adam Bartoš drekin at gmail.com
Sun Jun 12 08:56:05 EDT 2016


Hello,

I'm trying to employ code like https://code.activestate.com/recipes/572200/
at Python 2 startup. The problem is that sys.argv isn't polulated yet when
sitecustomize is executed. Is there any way around? I was thinking about
something like temporarily chaning sys.modules['sys'] or sys.__dict__ to
something that runs my code on PySys_SetArgv, but that doesn't work since
PySys_SetArgv doesn't invoke any hooks like __setitem__ on sys.__dict__. So
is there any way how to automatically run my code after sys.argv was set
but before executing the main script (in Python 2)?

Regards, Adam Bartoš



More information about the Python-list mailing list