I have a problem with the use function in Python. This is part of my main function:
def main(argv):
try:
opts, args = getopt.getopt(argv, 'hi:o:tbpms:', ['help', 'input=', 'output='])
if not opts:
print 'No options supplied'
usage()
except getopt.GetoptError,e:
print e
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
sys.exit(2)
if __name__ =='__main__':
main(sys.argv[1:])
and I also define the use function
def usage():
print "\nThis is the usage function\n"
print 'Usage: '+sys.argv[0]+' -i <file1> [option]'
but when I run my code like ./code.pyor ./code.py -h(it is executable), I got something other than Python help.
source
share