I'm playing around with optparse and created the code below. How do I
move that to a function and what variable do I pass?
[color=blue]
>From the documentation it seems like "options.optpar se_test" would have[/color]
the value zero if its option, either "-t" or "--test", is not detected
at the command line. When I issue "print options.optpars e_test" when no
command options are used, "None" is sent to the screen (IIRC)... Is a
proper check if a command line argument is not used to use the
following:
# being check
if options.optpars e_test <> 1:
print "test parameter NOT detected"
# end check
Thanks.
# begin program
#!/usr/bin/python
from optparse import OptionParser
import string
parser = OptionParser()
parser.add_opti on("-t", "--test", action="count", dest="optparse_ test",
help="testing optparse")
(options, args) = parser.parse_ar gs()
print options.optpars e_test
if options.optpars e_test == 1:
print "test parameter detected"
if options.optpars e_test <> 1:
print "test parameter NOT detected"
#parser.print_h elp()
# end program
move that to a function and what variable do I pass?
[color=blue]
>From the documentation it seems like "options.optpar se_test" would have[/color]
the value zero if its option, either "-t" or "--test", is not detected
at the command line. When I issue "print options.optpars e_test" when no
command options are used, "None" is sent to the screen (IIRC)... Is a
proper check if a command line argument is not used to use the
following:
# being check
if options.optpars e_test <> 1:
print "test parameter NOT detected"
# end check
Thanks.
# begin program
#!/usr/bin/python
from optparse import OptionParser
import string
parser = OptionParser()
parser.add_opti on("-t", "--test", action="count", dest="optparse_ test",
help="testing optparse")
(options, args) = parser.parse_ar gs()
print options.optpars e_test
if options.optpars e_test == 1:
print "test parameter detected"
if options.optpars e_test <> 1:
print "test parameter NOT detected"
#parser.print_h elp()
# end program
Comment