getopt issues

Raymond Hettinger vze4rx4y at verizon.net
Wed Aug 27 01:35:05 EDT 2003


[David Bear]

> I'm stumped.  Trying to follow the docs and .. failure.
>
> here's the args
>
> >>> args
>
'-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff 
-Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Phold
queue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCP
IP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus 
-t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n'
>
>
> I know, they're long.  sorry.  they just are.  and maybe thats the
> bug.
>
> here's what happens
>
> >>> a, b = getopt.getopt(args, 'APQn')
> >>> a
> []
> >>> b
>
'-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff 
-Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Phold
queue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCP
IP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus 
-t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n'
>
>
> not at all what the docs lead me to believe.  Is getopt buggy?

Normally, it is prudent to suspect your own code first rather
than the module.

In this case, getopt is expecting a list for the args argument which
normally comes from sys.argv.   Try this:

    args = args.split()
    a, b = getopt.getopt(args, 'APQn')

That will get you closer.
The next step is define the missing codes like -M.


Raymond Hettinger








More information about the Python-list mailing list