Typeerror: ‚Konten‘ Objekt ist nicht iterable
ich auf einem Skript gerade arbeite mit Tkinter und die Peewee ORM. Ich habe:
db = SqliteDatabase('data.db')
introspector = Introspector.from_database(db)
models = introspector.generate_models()
cities_list = []
account_obj = models['accounts']
recordset= account_obj.select()
for r in recordset:
city = str(r.city)
elapsed_hours = (time.time()-int(r.datetime))/3600
cities_list.append(str(r.city)+'-'+str(elapsed_hours))
master = tk.Tk()
variable = StringVar(master)
variable.set(cities_list[0]) # default value
w = OptionMenu(master, variable, *cities_list)
w.pack()
def ok():
print ("value is:" + variable.get())
v_list = variable.get().split('-')
print type(account_obj)
recordset = account_obj.select().where(account_obj.city.contains(v_list[0])).get()
for r in recordset:
r.datetime=int(time.time())
r.update()
button = Button(master, text="OK", command=ok)
button.pack()
mainloop()
An der zweiten select-Anweisung:
recordset = account_obj.select().where(account_obj.city.contains(v_list[0])).get()
Ich erhalte:
Traceback (most recent call last):
<class 'peewee.BaseModel'>
File "...lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "... myscript.py", line 46, in ok
for r in recordset:
TypeError: 'accounts' object is not iterable
Was mache ich falsch?
Im Allgemeinen gibt 'get()' nur eine Instanz zurück (falls vorhanden). Sie sollten es wahrscheinlich durch 'all()' ersetzen (was eine 'list' zurückgibt, die * iterable * ist) in der Zeile:' recordset = account_obj.select(). Where (account_obj.city.contains (v_list [0])) .get() '. Ich hoffe, das macht Sinn, da ich keine Erfahrung mit diesem Framework habe. – CristiFati
recordset = account_obj.select(). Wo (account_obj.city.contains (v_list [0])). All() AttributError: 'SelectQuery' Objekt hat kein Attribut 'all' – user61629
Ich hatte Angst, dass dies auftreten könnte. Versuchen Sie dann, '.get()' vollständig zu entfernen. – CristiFati