Feb-02-2021, 03:45 PM
I want to query table pop and write each row to a deferent file, this is code, but the code write the last row to all three files:
# Create a cursor object cur = conn.cursor() query = f"SELECT user, passwd,server FROM pop" cur.execute(query) for row in cur: list1 = ['1', '2', '3'] for i in range(len(list1)): f = open('mail%s' % i, 'w') print(row[0],row[1],row[2], file=f)