this is somewhat related to my earlier query..
Reading A Big File With Python
The problem was with runtime, so i was suggested to use sqlite3 database, and it reduced the time to millisecond, and I am very happy, now the only problem i have is, connecting to different database files in the same folder. All the database files have the same tables.
The code I am using, reads only the first one, and doesnt seem to check the other databases.
The output is when the teacher, enters students ID, it is supposed to return the related records if found in the database table.
my Code is something like this, But I am sure I am doing something wrong, pardon me if its a silly one, as using sqlite3 for the first time.
#other codes above not related to this part
databases = []
directory = "./Databases"
for filename in os.listdir(directory):
flname = os.path.join(directory, filename)
databases.append(flname)
for database in databases:
conn = sqlite3.connect(database)
conn.text_factory = str
cur = conn.cursor()
sqlqry = "SELECT * FROM tbl_1 WHERE std_ID='%s';" % (sudentID)
try:
c = cur.execute(sqlqry)
data = c.fetchall()
for i in data:
print "[INFO] RECORD FOUND"
print "[INFO] STUDENT ID: "+i[1]
print "[INFO] STUDENT NAME: "+i[2]
#and some other info
conn.close()
except sqlite3.Error as e:
print "[INFO] "+e
Thanks For Any guides
sudentIDdatabases = [os.path.join(directory, filename) for filename in os.listdir(directory)]; 2)with sqlite3.connect(database) as conn: ...print? Likeprint databasefor instance. What's the output?print len(data)to show how many records you are getting back. In general, people would be able to help you better if you post a single example that demonstrates the issue, and not omit possibly important code.