How a script can know if it has been called with the -i command line option?

Thomas Heller theller at ctypes.org
Thu Dec 21 13:28:18 EST 2006


Michele Simionato schrieb:
> The subject says it all, I would like a script to act differently when
> called as
> $ python script.py and when called as $ python -i script.py. I looked
> at the sys module
> but I don't see a way to retrieve the command line flags, where should
> I look?
> TIA,
> 
>           Michele Simionato
> 

I don't know how to get the command line flags, but the variable you are interested
in is this one:

from ctypes import *
print c_int.in_dll(pythonapi, "Py_InteractiveFlag")

;-)

Thomas




More information about the Python-list mailing list