Detecting -i in a script

Static Vagabond static at viralmind.org
Mon Apr 13 20:32:16 EDT 2009


I think getopt will help you achieve what you need.
http://docs.python.org/library/getopt.html

Here's a quick example:

import getopt
import sys

try:
     opts, args = getopt.getopt(sys.argv[1:], "-i:vo:vhb?")
except getopt.GetoptError, err:
     helpCommand() # defined elsewhere.
     sys.exit()

for o, a in opts:
     if o == "-i":
         inputFile = a
     elif o == "-o":
         outputFile = a
     elif o == "-?" or "-h":
         helpCommand() # defined elsewhere.
     elif o == "-b":
     	blank() # defined elsewhere.

Static.


Marek Szuba wrote:
> On 2009-04-13, Chris Rebert <clp2 at rebertia.com> wrote:
> 
>> The sys.flags.interactive bool.
>>
>> Details: http://docs.python.org/library/sys.html#sys.flags
> Hmm, "New in version 2.6"... Are you aware of any way of extracting
> this information in older versions of Python? My code needs to be
> 2.3-compatible.
> 



More information about the Python-list mailing list