gpt4 book ai didi

python代码问题

转载 作者:行者123 更新时间:2023-11-28 19:36:12 24 4
gpt4 key购买 nike

我有这个代码:

class Check(webapp.RequestHandler):
def get(self):
user = users.get_current_user()

be = "SELECT * FROM Benutzer ORDER BY date "
c = db.GqlQuery(be)

for x in c:
if x.benutzer == user:
s=1
break
else:
s=2
if s is 0:
self.redirect('/')

检查用户是否注册。但它给了我一个错误:

Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/Users/zainab_alhaidary/Desktop/الحمد لله/check.py", line 23, in get
if s is 0:
UnboundLocalError: local variable 's' referenced before assignment

我该怎么办???

最佳答案

定义 s 之前为其分配一个值(同时更改 s 上的测试):

user = users.get_current_user()

be = "SELECT * FROM Benutzer ORDER BY date "

c = db.GqlQuery(be)

s=0 # <- init s here

for x in c:
if x.benutzer == user:
s=1
break
else:
s=2
if s == 0: # <- change test on s
self.redirect('/')

关于python代码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3458950/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com