B
Bob
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?
at the command line. When I issue "print options.optparse_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.optparse_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_option("-t", "--test", action="count", dest="optparse_test",
help="testing optparse")
(options, args) = parser.parse_args()
print options.optparse_test
if options.optparse_test == 1:
print "test parameter detected"
if options.optparse_test <> 1:
print "test parameter NOT detected"
#parser.print_help()
# end program
move that to a function and what variable do I pass?
the value zero if its option, either "-t" or "--test", is not detectedFrom the documentation it seems like "options.optparse_test" would have
at the command line. When I issue "print options.optparse_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.optparse_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_option("-t", "--test", action="count", dest="optparse_test",
help="testing optparse")
(options, args) = parser.parse_args()
print options.optparse_test
if options.optparse_test == 1:
print "test parameter detected"
if options.optparse_test <> 1:
print "test parameter NOT detected"
#parser.print_help()
# end program