标签: 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',)?
答案 0 :(得分:0)
返回值('html',)是tuple,因此您只需访问其第一个元素:
tuple
rows[5][0]
获取
'html'