我正在使用Python 2.7和postgresql 9.1.试图从查询中获取字典,我已经尝试了这里描述的代码:http: //wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL
import psycopg2
import psycopg2.extras
conn = psycopg2.connect("dbname=mydb host=localhost user=user password=password")
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute ("select * from port")
type(cur.fetchall())
Run Code Online (Sandbox Code Playgroud)
它打印下一个答案:
<type 'list'>
Run Code Online (Sandbox Code Playgroud)
打印项目本身,告诉我它是列表.除外答案是字典.
编辑:
尝试下一个:
ans = cur.fetchall()[0]
print ans
print type(ans)
Run Code Online (Sandbox Code Playgroud)
回报
[288, 'T', 51, 1, 1, '192.168.39.188']
<type 'list'>
Run Code Online (Sandbox Code Playgroud) 我试图在html代码中隐藏一些col.使用MDN colgroup和col添加,我正在玩cols的样式.
在<td>与内容文本"可见的"在所有的浏览器(好)可见,在与内容文本"隐藏"在铬(坏)可见和隐藏在Firefox和边缘.(好).
我可以重新创建问题的最短代码在这里:
<!doctype html>
<html>
<head>
<title>css example</title>
<style type='text/css'>
col.visible {}
col.hidden { visibility:collapse; }
</style>
</head>
<body>
<table border='1'>
<colgroup>
<col class='visible'>
<col class='hidden'>
<tbody>
<tr>
<td>visible</td>
<td>hidden</td>
</tr>
</tbody>
</colgroup>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) colgroup ×1
css ×1
dictionary ×1
html-table ×1
postgresql ×1
psycopg2 ×1
python ×1
python-2.7 ×1