python-by-example-150-chall.../challenges139-145/challenge-144_.py
2021-12-08 20:19:52 +09:00

23 lines
502 B
Python

import sqlite3
file = open("Booklist.txt","w")
with sqlite3.connect("BookInfo.db") as db:
cursor=db.cursor()
cursor.execute("SELECT Name from Authors")
for x in cursor.fetchall():
print(x)
print()
selectauthor=input("Enter an author's name: ")
print()
cursor.execute("SELECT * from Books WHERE Author=?", [selectauthor])
for x in cursor.fetchall():
newrecord=str(x[0])+" - "+x[1]+" - "+x[2]+" - "+str(x[3])+"\n"
file.write(newrecord)
file.close()
db.close()