zoukankan      html  css  js  c++  java
  • python3 读取照片写入数据库postgres

    import psycopg2
    import os
    
    
    
    path = 'D:\photo\'
    conn = psycopg2.connect(database="****", port='*****',
                            user="***", password="*****", host="202.38.*.*"
                            )
    
    cur = conn.cursor()
    
    cur.execute('''truncate table app.xh_image;''')
    conn.commit()
    for dirpath,dirnames,filenames in os.walk(path):
        print(dirpath,dirnames,filenames)
        for filepath in filenames:
            file_path = path + '\' + filepath
            xh = filepath.split('.')[0]
            print(file_path,xh)
            with open(file_path,'rb')as img_open:
                img_buffer = img_open.read()
            params = psycopg2.Binary(img_buffer)
    
            cur.execute('''insert into app.xh_image(xh,image) values('{}',{});'''.format(xh,params))
    conn.commit()
    conn.close()
    

      

  • 相关阅读:

    快排
    排序算法
    运算符
    二叉树
    递归
    队列
    栈(没写完)
    绘制双坐标轴的图形3-不同的plot类型
    绘制双坐标轴的图形2-不同的plot类型
  • 原文地址:https://www.cnblogs.com/zzay/p/13957760.html
Copyright © 2011-2022 走看看