Parse command line options

2005-04-18 Thread hue
I am trying to parse command line options using getopt module.

I have written the following Code

import string

import getopt

def usage():
print '''haarp_make.py -- uses getopt to recognize options

Options: -n  -- No
 -t  -- Time
 -h  -- help
 -i  -- image_file
 -o  -- Output:filename'''

sys.exit(1)

def main():


try:

opts,args = getopt.getopt(sys.argv[1:], 'n:t:h:i:o:',
["Number=","time=","help=","image_file=","Output Filename="])

except getopt.GetoptError:
print 'Unrecognized argument or option'
usage()
sys.exit(0)



I have gone through getopt module from the help in python Library, but
i couldnot proceed from here.

My Task is

python  MyScriptName.py  n  t  h  i  o

How to parse those arguments, i is an Image File.
Please try to give some comments.
Hoping for a reply.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parse command line options

2005-04-18 Thread hue
Thanks for your reply, I have used some of your ideas in my Code.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parse command line options

2005-04-18 Thread hue
Thanks for your reply, I have used some of your ideas in my Code.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Tkinter...

2005-04-19 Thread hue
Hello

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Run Unix shell command $ parse command line arguments in python

2005-04-22 Thread hue
Thanks for your reply

I started writing the script.. I have gone through documentation for
getopt

import string, getopt, sys

def usage():

print '''myscript.py -- uses getopt to recognize options
Options: -n  -- No
 -t  -- T
 -h  -- help
 -i  -- i
 -o  -- Output:filename'''
sys.exit(1)
def main():

print "SYS ARGV: ", ",".join(sys.argv)

# Define the Options

Options = {
'n:': 'Number=',
't:': 'T',
'h' : 'help',
'i' : 'i',
'o' : 'Output_file',
}
shortOpts = ''.join(Options.keys())
longOpts  = Options.values()


try:
(opts, args) = getopt.getopt(argv[1:], shortOpts, longOpts)
except getopt.error, msg:
print "Unrecognized argument or option"
# end try


for (opt, arg) in opts:

if opt in ('-n', '--Number'):
print '-n is the Number', Number
sys.exit()

elif opt in ('-t', '--T'):
print '-t is the T', T
sys.exit()

elif opt in ('-h', '--help'):
usage()
print " "
sys.exit()

elif opt in ('-i', '--i'):
print " I", i


elif opt  in ('-o', '--Output Filename'):
print "Output", Output


# end if
   # end for

print "OPTS: ", ",".join([repr(o) for o in opts])
print "ARGS: ", ",".join(args)

if __name__ == "__main__":
main()

with the above code, I am planning to do command line parsing. But how
to run unix shell command? DO i have to use os Module/  import command?

How should i proceed further, to
 import commands
 commands.getstatusoutput('ls /bin/ls')

Please suggest me some ideas how to proceed further

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list