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

Tim Golden tjgolden at gmail.com
Fri Dec 22 12:46:58 EST 2006


> > Michele Simionato wrote:
> >> 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.

[Michael B. Trausch]
> There is a set of utilities that have UNIX-like ps behavior, but, as is
> typical for Windows, they don't work the way their UNIX and UNIX-like
> counterparts do.  Does 'ps' work from within Cygwin, and if so, would
> redistributing that be an option?

If you wanted to get the command line from within
Windows, you could use win32api.GetCommandLine.
I think the OP's on Linux, and in any case you'd have
to do your own parsing, but...

<dump>
c:\>python -i
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> win32api.GetCommandLine ()
'python -i'
>>>
</dump>

TJG




More information about the Python-list mailing list