pass named parameters to python

2005-02-08 Thread John Leslie
I am converting a korn shell script to python and want to be able to
pass named arguments into python e.g -firstparam -secondparam

Can this be done?
-- 
http://mail.python.org/mailman/listinfo/python-list


passing arguments like -JOB

2005-02-10 Thread John Leslie
I am porting a script from Korn Shell to python and want to pass named
parameters like -JOB 123456 -DIR mydir

I can get it to work passing --JOB and --DIR but not -JOB and -DIR

Any ideas?

Current code :

try:
options, xarguments = getopt.getopt(sys.argv[1:], '', ['JOB=',
'DIR=', 'ERR=', 'GRP=', 'TST=', 'JNM=', 'DAT=',])
except getopt.error:
print 'Error: You tried to use an unknown option'
sys.exit(1)
JOB = ''
for o,a in options[:]:
print 'here2'
print o
print a
if o == '--JOB':
   JOB = a
   print JOB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: passing arguments like -JOB

2005-02-11 Thread John Leslie
Thanks...it worked perfectly.
Brilliant!!

JL


Duncan Booth <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> John Leslie wrote:
> 
> > I am porting a script from Korn Shell to python and want to pass named
> > parameters like -JOB 123456 -DIR mydir
> > 
> > I can get it to work passing --JOB and --DIR but not -JOB and -DIR
> > 
> > Any ideas?
> > 
> Unfortunately (for you), I think you will find most or all of the existing 
> ways to parse command line options in Python follow the POSIX convention 
> for arguments, i.e. single letter options are introduced with a single - 
> and multi-letter options are introduced with --.
> 
> My guess is that if you can't change whatever generates the command lines 
> to conform to this convention you will have to write your own code to do 
> the processing.
> 
> Alternatively you might get by by hacking the command line in your Python 
> code:
> 
>for i, opt in enumerate(sys.argv):
>if opt in ('-JOB','-DIR', '-ERR', '-GRP', '-TST', '-JNM', '-DAT'):
>   sys.argv[i] = '-'+opt
> 
>... and then use getopt or optparse here ...
> 
> It isn't pretty, but so long as those values don't turn up elsewhere in the 
> command line it ought to work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Wishful thinking : unix to windows script?

2005-03-04 Thread John Leslie
Or does anyone have a python script which takes a standard unix
command as an argument and runs the pyton/windows equivalent on
windows?
-- 
http://mail.python.org/mailman/listinfo/python-list