获取长文本列

2024-04-25 13:40:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用Python3.6从MySql数据库获取结果时遇到了一个问题。 长文本是转换为字符串的numpy数组。你知道吗

当我检查数据库并查看img_array列时,一切都很好。所有数据都被写入。你知道吗

接下来,我尝试检索文本列,如下所示:

con = .. # SQL connection which is successful and working fine
cur = con.cursor() # Getting the cursor
cur.execute('SELECT img_array FROM table WHERE id = 1')
result = cur.fetchone()[0] # Result is a tuple with the array at 0
print(result)
[136 90 87 ... 66 96 125]

这里的问题是...就像一个字符串。我错过了所有的价值观。你知道吗

当我尝试以下方法时,效果很好:

cur.execute('SELECT img_array FROM table LIMIT 1')
result = cur.fetchone()[0] # this gives me the entire string in the DB
print(result)
# The entire array will be printed here without missing values

我真的不知道如何通过python获取带有where子句的列。你知道吗

有什么想法吗?你知道吗

编辑:好的,上次编辑错误。。。我又检查了一遍,缓冲的游标并没有改变它。我很困惑,因为它似乎起作用了。你知道吗


Tags: the字符串from文本数据库imgexecuteis