python将目标检测txt数据导入到mysql数据库中
代码段
import pymysql
# 连接数据库
conn = pymysql.connect(
host='nj-cdb-kxg7ixmv.sql.tencentcdb.com', port=63975,
user='root', password='P@ssw0rd500', database='test',
charset='utf8')
cursor = conn.cursor()
f = open(r'info.txt', "r", encoding='utf-8')
for line in f:
value_list = list(map(lambda x: '%s' % x, line.split()))
val = (value_list[0], value_list[1], value_list[2], value_list[3],
(value_list[4]), value_list[5], value_list[6], value_list[7])
cursor.execute('insert into python_test(image_id, image_name, cla, x1, y1, x2, y2, conf) values (%s, %s, %s, %s, %s, %s, %s, %s)',val)
f.close()
cursor.close()
conn.commit()
conn.close()
结果展示