Python 3.x 使用python从postgres数据库检索多个基于文件的存储图像
我想使用PythonJupyter笔记本检索存储在数据表中的图像,并将它们保存在桌面文件夹中,但无法理解我在哪里出错Python 3.x 使用python从postgres数据库检索多个基于文件的存储图像,python-3.x,postgresql,Python 3.x,Postgresql,我想使用PythonJupyter笔记本检索存储在数据表中的图像,并将它们保存在桌面文件夹中,但无法理解我在哪里出错 def write_file(data, filename): # Convert binary data to proper format and write it on Hard Disk with open(filename, 'wb') as file: file.write(data) cursor.execute("SELECT * from m
def write_file(data, filename):
# Convert binary data to proper format and write it on Hard Disk
with open(filename, 'wb') as file:
file.write(data)
cursor.execute("SELECT * from mydb where id = {0}")
record = cursor.fetchall()
for row in record:
ID= row[0]
print("Id = ", row[0])
image = row[1]
photo= r"C:\Users\my_profile\Desktop\outputimage\img{0}.JPG".format(str(ID))
write_file(image, photo)
看来没问题。对于SELECT语句的星号符号,您确定第一列是
ID
,第二列是yourBlob
?我的意思是,您已经了解了列顺序的表创建DDL。谢谢您的帮助。我犯了一个小错误,现在已经解决了。不客气