2
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]

顧客の詳細を取得するために上記のコードを使用しますが、実行すると次のエラーが発生します:

  File "G:\ICT\SADS.py", line 111, in editdetails
print "Customer ID : " , row[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

そして、それは本当に私の神経質になり、whileループまたは行の行を使用しようとしましたが、機能しません-助けてください:(

4

1 に答える 1

6
row = cur.fetchone()
if row is None:
    print "Telephone number not found"
else:
    print "Customer ID : " , row[0]
于 2013-02-07T20:46:44.323 に答える