1
我正在爲您的帳戶系統上的此Python Credits工作,但似乎我的最後一個for循環未運行,導致未定義time_set。有誰知道爲什麼我的最後一個for循環沒有運行。出於安全原因已刪除數據庫詳細信息。這裏是我的代碼:MySQLDb上的名稱錯誤
from time import sleep
import MySQLdb
db = MySQLdb.connect(host="", # your host, usually localhost
user="", # your username
passwd="", # your password
db="") # name of the data base
cursor = db.cursor()#Defines a cursor allowing me to execute SQL commands
def timer(time, _print=False):
if time == 0:
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
cursor.execute("UPDATE Accounts SET Credits = 0 WHERE Username = '{1}';".format(creds, name))
return ''
else:
if _print: print time
sleep(1)
return timer(time - 1, _print)
name = raw_input("What username would you like to add credits to?:")
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
creds = input("How many credits would you like to add to the account?")
for test in cursor.fetchall():
creds = creds + test[3]
cursor.execute("UPDATE Accounts SET Credits = {0} WHERE Username = '{1}';".format(creds, name))
for row in cursor.fetchall():
time_set = creds * 60
print time_set
timer(time_set, True)