在python中使用Psycopg2模块获取数据

时间:2015-10-22 06:23:07

标签: python-2.7 psycopg2 postgresql-9.3

当我尝试运行以下基本python脚本以使用psycopg2模块在postgresql数据库中获取数据时:

cur.execute("""SELECT project from project_tlb""")
rows=cur.fetchall()
print rows[5]

我得到的上述输出是

('html',)

表格中的值是html,其类型为' text'。任何建议如何只获取值html而不是(' html',)?

1 个答案:

答案 0 :(得分:0)

返回值('html',)tuple,因此您只需访问其第一个元素:

rows[5][0]

获取

'html'