The with
statement was added in Python 2.5; you must be using a version older than that.
Either upgrade Python, or not use the with
statement; you could use try
/finally
here to ensure the file object is closed:
f = open('test.txt')
try:
for row in f:
# ...
finally:
f.close()
You should really use SQL parameters to interpolate the row data instead of using string manipulation:
for row in f:
params = (row.strip(),)
cur.execute("DELETE FROM filterstagetbl where filtersetidn IN (select filtersetidn from filtersettbl where name = ?",
params)
cur.execute("DELETE FROM filtersetaccesstbl where filtersetidn IN (select filtersetidn from filtersettbl where name = ?",
params)
cur.execute("DELETE FROM filtersetmembertbl where filtersetidn IN (select filtersetidn from filtersettbl where name = ?",
params)
cur.execute("UPDATE filtersettbl set status = 4 where name = ?",
params)
where you'll need to adjust the parameter placeholder syntax for your database adapter. sqlite3
uses ?
, MySQLdb uses %s
, as does psycopg2
.