gpt4 book ai didi

python - SQLAlchemy > 类型错误 : 'instancemethod' object does not support item assignment

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:25 26 4
gpt4 key购买 nike

这是我得到的:


from sqlalchemy import *
from sqlalchemy.orm import *
from web.models.card import *
connectionString = "postgresql://www:www@localhost/prod"
databaseEngine = create_engine(connectionString)
sessionFactory = sessionmaker(autoflush = True, autocommit = False, bind = databaseEngine)
session = sessionFactory()
CardsCollection = session.query(card).all()
_content = {}
for index in range(0, len(CardsCollection)):
c = CardsCollection[index]
_content[index] = c
print json.dumps(_content)

这里是错误:


Traceback (most recent call last):
File "/home/src/py/raspberry/src/dictionaryTest.py", line 15, in
CardsCollection = session.query(card).all()
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py", line 1453, in all
return list(self)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py", line 1676, in instances
rows = [process[0](row, None) for row in fetch]
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 2234, in _instance
populate_state(state, dict_, row, isnew, only_load_props)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 2113, in populate_state
populator(state, dict_, row)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/strategies.py", line 127, in new_execute
dict_[key] = row[col]
TypeError: 'instancemethod' object does not support item assignment

有人可以帮我解决这个问题吗?我已经尝试了一些东西,并研究了字典是如何工作的……但它并没有让我大吃一惊。

[编辑奇怪的分辨率] 显然,覆盖卡片模型上的 self.__dict__(self) 方法就是这样做的。不过,我不完全确定为什么。

最佳答案

__dict__special attribute保持实例的当前状态,用方法覆盖它肯定会导致麻烦。

关于python - SQLAlchemy > 类型错误 : 'instancemethod' object does not support item assignment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3653690/

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