I'm appreciate to your help in my issue.
I want to append my response query into exist CSV file. I'm implement this by this example but from unknown reason - the output file stay empty.
This is minimal snippet of my code:
import psycopg2
import numpy as np
# Connect to an existing database
conn = psycopg2.connect(dbname="...", user="...", password="...", host="...")
# Open a cursor to perform database operations
cur = conn.cursor()
f = open('file_name.csv', 'ab') # "ab" for appending
cur.execute("""select * from table limit 10""") # I have another query here but it isn't relevant.
cur_out = np.asarray(cur.fetchall())
Until here it works perfect. When I print(cur_out)
, I got desired output. But in the next step:
np.savetxt(f, cur_out, delimiter=",", fmt='%s')
The file stay empty and I didn't find the reason for that.
Can you help me please?
Thankes for helpers.