Python二维码生成

依赖包生成:

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

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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()


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 linjk121@163.com.