M
Matthew Lear
Hello,
I'm having problems getting getopt to function correctly. Basically, no
exception is being raised if no argument is passed to the code snippet
below. I've read the Python documentation and tried example code from
various sources which should cause an exception, only they don't. I've
also tried executing the code on different machines too but to no avail.
I'm sure I'm obviously doing something wrong but can't determine what.
Any help would be much appreciated indeed.
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv, "h:", ["help"])
except getopt.GetoptError:
print "error"
sys.exit(2)
If no args are passed when the script is run there is no exception
raised. Why? Surely the "h:" means that this option must be passed?
Thanks,
-- Matt
I'm having problems getting getopt to function correctly. Basically, no
exception is being raised if no argument is passed to the code snippet
below. I've read the Python documentation and tried example code from
various sources which should cause an exception, only they don't. I've
also tried executing the code on different machines too but to no avail.
I'm sure I'm obviously doing something wrong but can't determine what.
Any help would be much appreciated indeed.
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv, "h:", ["help"])
except getopt.GetoptError:
print "error"
sys.exit(2)
If no args are passed when the script is run there is no exception
raised. Why? Surely the "h:" means that this option must be passed?
Thanks,
-- Matt