Python postgres输出格式

Python postgres输出格式,python,postgresql,Python,Postgresql,我使用的是psycopg2,我想知道是否有一种方法可以从SELECT语句生成更清晰的输出 我的数据在数据库中如下所示: ("Apple" user:(Apple) tag:(Apple)) 当我通过psycopg2向下拉数据时,它看起来是这样的: ('("Apple" user:(Apple) tag:(Apple))') 我希望它不要在每行的前面和结尾追加这些字符,有更干净的方法吗?代码如下 cur.execute(''' select field from table;

我使用的是psycopg2,我想知道是否有一种方法可以从SELECT语句生成更清晰的输出

我的数据在数据库中如下所示:

("Apple" user:(Apple) tag:(Apple))
当我通过psycopg2向下拉数据时,它看起来是这样的:

('("Apple" user:(Apple) tag:(Apple))')
我希望它不要在每行的前面和结尾追加这些字符,有更干净的方法吗?代码如下

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

rows = cur.fetchall()

for row in rows:
     # Write rows to text file
     writer.write(row + '\n')

您可以在写入文件之前处理该行,例如:

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