2

I'm using psycopg2 and I'd like to know if there's a way to generate some cleaner output from my SELECT statements.

My data looks like this in the database:

("Apple" user:(Apple) tag:(Apple))

When I pull the data down through psycopg2, it looks like this:

('("Apple" user:(Apple) tag:(Apple))')

I'd like it to not append those characters to the front and end of each row, is there a cleaner method to do it? Code follows.

cur.execute(''' 
    select field from table;
    ''')

rows = cur.fetchall()

for row in rows:
     # Write rows to text file
     writer.write(row + '\n')
1
  • or writer.write(row[0][1:-1] + '\n') Commented Nov 20, 2013 at 23:57

1 Answer 1

0

You could process the row before you write to file, for example:

for row in rows:
     # Write rows to text file
     user = row[0]
     tag = row[1]
     writer.write(user + ' ' + tag + '\n')
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.