sean-keys
asked on
Simple Python Syntax Problem
Hi the following code gives me the error below. I have never messed with python so any input would be appreciated.
Thanks!
includes# ./lllog.py
Traceback (most recent call last):
File "./lllog.py", line 45, in <module>
main(sys.argv[1:])
File "./lllog.py", line 18, in main
except getopt.GetoptError:
NameError: global name 'getopt' is not defined
Thanks!
includes# ./lllog.py
Traceback (most recent call last):
File "./lllog.py", line 45, in <module>
main(sys.argv[1:])
File "./lllog.py", line 18, in main
except getopt.GetoptError:
NameError: global name 'getopt' is not defined
#!/usr/bin/python
# import MySQL module
import MySQLdb
# import sys module for argument processing etc
import sys
def main(argv):
fileName = "unknown"
hfJobId = 444
message = "hylafax update"
type = "FAX"
sendto = 555
action = "update"
try:
opts, args = getopt.getopt(argv, "ha:", ["help"])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt == '-a':
action = arg
print "action arg is", action
# connect
db = MySQLdb.connect(host="172.16.1.90", user="hylafax", passwd="pass",
db="pass")
# create a cursor
cursor = db.cursor()
# execute SQL statement
cursor.execute("""INSERT INTO lablynk_send_log (fileName, hfJobId, message, type, sendto) VALUES ("test",
"test","test", "FAX", "test")""")
# get ID of last inserted record
print "ID of inserted record is ", int(cursor.insert_id())
if __name__ == "__main__":
main(sys.argv[1:])
def usage():
print "build usage messages"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.