SQLAlchemy TypeError: instancemethod does not support item assignment

2024-09-25 00:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到的是:


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)

错误就在这里:

^{pr2}$

有人能帮我解决这个问题吗?我尝试了一些方法,研究了字典的工作原理。。。但它不是冲着我跳出来的。在

很明显,在卡片模型上重写self.__dict__(self)方法就是这样做的。不过,我不太清楚原因。在


Tags: 方法fromimportselfindexsqlalchemysessionwww