conn = sqlite3.connect('SADS.db')
cur = conn.cursor()
print " "
choice = raw_input("Does the Customer know their user ID? Y/N : ")
if choice == "N":
number = raw_input("What is their phone number? : ")
cur.execute("SELECT * FROM customers WHERE Telephone = (?)", (number,))
row = cur.fetchone()
print "Customer ID : " , row[0]
Run Code Online (Sandbox Code Playgroud)
我使用上面的代码来检索客户详细信息 - 但是当我这样做时,我收到以下错误:
File "G:\ICT\SADS.py", line 111, in editdetails
print "Customer ID : " , row[0]
TypeError: 'NoneType' object has no attribute '__getitem__'
Run Code Online (Sandbox Code Playgroud)
它真的让我神经紧张我已经尝试使用while循环或行中的行但它不起作用 - 请帮助:(
row = cur.fetchone()
if row is None:
print "Telephone number not found"
else:
print "Customer ID : " , row[0]
Run Code Online (Sandbox Code Playgroud)