I am fairly new to Python and trying to figure out way to use variables from file as described below.
I have a file query.txt
query1="select count(*) from table1;"
query2="select count(*) from table2;"
My main program:
conn=connect_db()
print >>log,"connection successful"
c=conn.cursor()
with open('query.txt') as fp:
for line in fp:
print line
i=1
query="query"+str(i) #If I print query I get query1
#I am looking to pass query1 as argument, to execute first query
c.execute(query);
r=c.fetchone()
print r
i+=1
In shell I would use c.execute($query) and it would replace it with it's assigned value. How do I achieve it with Python?
Appreciate your help and guidance.