Python二维码生成

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Linjingke32/article/details/82427292

        依赖包生成:

        

        PyMySQL安装(Python3.x不支持MySQLdb了)

        

        代码:

        

#!/usr/bin/python3

import pymysql
import qrcode
import os

if not os.path.exists('qrcode'):
    os.mkdir('qrcode')
    
os.chdir(os.getcwd() + '/qrcode')

db = pymysql.connect(host="xxxx", port=xxxx,
                     user="xxxx", passwd="xxxx", 
                     db="xxxx")

cursor = db.cursor()

sql = "SELECT * FROM xxx"
try:
    cursor.execute(sql)
    results = cursor.fetchall()
    for row in results:
        result = row[3]
        img = qrcode.make(result)
        img.save('%s.png' % (result))
except:
    print("Error: unable to fetch data")

db.close()

        

猜你喜欢

转载自blog.csdn.net/Linjingke32/article/details/82427292