I'm using pymysql in python to work with a mysql server, and I'm in need of some crossreferencing of different columns.
To do this I apply a for loop in python, with
for i in range(10):
sqlstat = 'select refs from `pcite` where id = id_paper(i) ;'
But this doesn't work. The problem seems to be the iterater i. Is there a way around this?
As I said in the comment, this has nothing to do with loops. It is just that your code is not code, but simply a string. If you need a string to contain the result of calling a function, then you need to take the call outside of the string, and interpolate the result:
sqlstat = 'select refs from `pcite` where id = {};'.format(id_paper(i))
Note however that since this is an SQL statement, you should not be interpolating values at all, but passing them to the execute method:
sqlstat = 'select refs from `pcite` where id = %s;'
cursor.execute(sqlstat, [format(id_paper(i)])