【发布时间】:2012-11-11 11:52:33
【问题描述】:
我是 Python 2.6 的新手。我一直在尝试在我的 Python 程序中取回 yyyy-mm-dd hh:m:ss 格式的日期 datetime 值。在 Python 中检查列类型时出现错误:'buffer' object has no attribute 'decode'。我想使用strptime() 函数来拆分日期数据并使用它,但我找不到如何将缓冲区转换为字符串。以下是我的代码示例(也可以使用here):
conn = sqlite3.connect("mrp.db.db", detect_types=sqlite3.PARSE_DECLTYPES)
cursor = conn.cursor()
qryT = """
SELECT dateDefinitionTest FROM t
WHERE IDproject = 4 AND IDstatus = 5
ORDER BY priority, setDate DESC
"""
rec = (4,4)
cursor.execute(qryT,rec)
resultsetTasks = cursor.fetchall()
cursor.close() # closing the resultset
for item in resultsetTasks:
taskDetails = {}
_f = item[10].decode("utf-8")
我得到的例外是:
'buffer' object has no attribute 'decode'
【问题讨论】:
-
请显示您的代码和确切的错误。
-
pastie.org/5360165 dateDefinitionTest 是 datetime 的 sqlite3 字段
-
我得到的错误:** 'buffer' 对象没有属性 'decode' **
标签: python sqlite python-2.6