SQLAlchemy Hands On
SQLAlchemy Hands On
db_string = "sqlite:///tests.db"
db = create_engine(db_string)
#create
db.execute("CREATE TABLE players (plyid text, plyname text, runs text)")
db.execute("INSERT INTO players (plyid, plyname, runs) VALUES('10001',
'ply1','100'), ('10002' , 'ply2', '80'),('10003','ply3','65'),
('10004','ply4','95'),('10005','ply5','99')")
# Read
result_set=db.execute("SELECT * FROM players")
s=list()
for r in result_set:
s.append(r)
#Update
#Delete
print(s)
print(q)
print(e)
s=str(s)
q=str(q)
e=str(e)
with open(".hidden.txt",'w') as f:
f.write(s)
with open(".hidden1.txt",'w') as f:
f.write(q)
with open(".hidden2.txt",'w') as outfile:
outfile.write(e)
###################################################################################