|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 fc5igm 于 2021-7-9 22:48 编辑
- # coding:utf-8
- class multi_import():
- def __init__(self):
- self.data=[]
- def insert(self,*item):
- raw=list(item)
- for i in range(len(item)):
- if type(raw[i])!=str:
- raw[i]=str(raw[i])
- raw=tuple(raw)
- self.data.append(f"{raw}")
- def print(self):
- return ','.join(self.data)
- def clear(self):
- self.data.clear()
- if __name__ == '__main__':
- import pymysql
- # 连接数据库
- conn = pymysql.connect(
- host='localhost',
- port=3306,
- user=#你的用户名,
- password=#你的密码,
- db=#你的数据库
- )
- # 拿到游标
- cursor = conn.cursor()
- minp=multi_import()
- #假设给field1到field3录值x,y,z十次
- x='x'
- y='y'
- z=1
- for i in range(10):
- minp.insert(x,y,z)
- cursor.execute(
- f"insert into #table_name(field1,field2,field3) values{minp.print()};")
- minp.clear()
- cursor.close()
- conn.close()
复制代码
写的自用的小程序,用法在批注里已经写明 |
|