I'm in the process of learning sqlalchemy and am hoping I can get some clarification on this script. I've already ran the initial program that creates the tables and inserts data so I'm guessing there is an underlying issue where the metadata isn't getting saved? If anyone can provide some feedback on this I would really appreciate it.
from sqlalchemy import (Column, MetaData, Integer, Text, Table)
from sqlalchemy import create_engine
engine = create_engine('sqlite:///data.db', echo=False)
metadata = MetaData(bind=engine)
# example 1
gamelist = Table('MLBGamelist', metadata, autoload=True)
for x in gamelist.c:
print(x)
#RETURNS#
MLBGamelist.event_id
MLBGamelist.game_ref
MLBGamelist.game_datetime
# example 2
gamelist = metadata.tables['MLBGamelist']
for x in gamelist.c:
print(x)
#RETURNS#
Traceback (most recent call last):
File "table_tools.py", line 15, in <module>
gamelist = metadata.tables['MLBGamelist']
KeyError: 'MLBGamelist'