を持っていない私はこのチュートリアルからコードスニペットを使用しようとしていた。 http://newcoder.io/scrape/part-4/SQLAlchemyの1.2はAttributeError:「リスト」オブジェクトが属性「セッション」
次は、クラス定義を含むファイルです:
from sqlalchemy.orm import sessionmaker
from .models import Deals, db_connect, create_deals_table
class Test(object):
def __init__(self, args):
"""
Initializes database connection and sessionmaker.
Creates deals table.
"""
engine = db_connect()
create_deals_table(engine)
self.Session = sessionmaker(bind=engine)
def add_item(self):
session = self.Session()
tester = Deals(title="test 3 deal",location='here', price=2.00)
session.add(tester)
session.commit()
Test.add_item(args)を呼び出すと、次のエラーが生成されます。
(sql) [[email protected] heap]$ python heap.py test Traceback (most
recent call last): File "heap.py", line 13, in <module>
main(sys.argv) File "heap.py", line 8, in main
Test.add_item(args) File "/home/bucket/src/heap/game/engine.py", line 17, in add_item
session = self.Session() AttributeError: 'list' object has no attribute 'Session'
コードは正常に動作し、クラス定義のないPythonスクリプトと同じコードを実行したときに行が追加されました。