Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用python从postgres数据库检索多个基于文件的存储图像_Python 3.x_Postgresql - Fatal编程技术网

Python 3.x 使用python从postgres数据库检索多个基于文件的存储图像

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

我想使用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 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。谢谢您的帮助。我犯了一个小错误,现在已经解决了。不客气