用python将txt数据表转为mysql插入语句
来源:互联网 发布:mac中文解压软件 编辑:程序博客网 时间:2024/05/29 02:10
源码下载:
https://pan.baidu.com/s/1bpKnVK7
结果截图
程序源码:
def write_sql(filename,text): try: fh = open(filename, "w", encoding="utf8") fh.write(text) except EnvironmentError as err: print("ERROR", err) else: print("Saved skeleton", filename) finally: if fh is not None: fh.close()def read_data(filename): text = [] for line in open(filename,encoding="utf8"): line_text = line.strip().split("\t") text.append(line_text) return textdef create_data(text,model): string = "" for t in text: string += model.format(t)+"\n" return stringread_directory = "data/"write_directory = "sql/"read_file = ("status.txt","admin.txt","account.txt","personinfo.txt","transaction_type.txt","transaction_log.txt")write_file = ("status.sql","admin.sql","account.sql","personinfo.sql","transaction_type.sql","transaction_log.sql")model = ("insert into status values({0[0]},\"{0[1]}\");", "insert into admin values({0[0]},\"{0[1]}\",\"{0[2]}\");", "insert into account values({0[0]},\"{0[1]}\",\"{0[2]}\",{0[3]},{0[4]});", """insert into personinfo values({0[0]},{0[1]},"{0[2]}",{0[3]},"{0[4]}",{0[5]},"{0[6]}","{0[7]}");""", "insert into transaction_type values({0[0]},\"{0[1]}\");", "insert into transaction_log values({0[0]},{0[1]},{0[2]},{0[3]},\"{0[4]}\",{0[5]});")lens = len(read_file)for i in range(0,lens): write_sql(write_directory+write_file[i],create_data(read_data(read_directory+read_file[i]),model[i]))
阅读全文
0 0
- 用python将txt数据表转为mysql插入语句
- 将txt转为dataset
- awk读取txt生成mysql插入语句
- python 将一个目录下word转为txt第三版
- ubuntu系统 python代码将.txt文件转为.xml文件
- MySQL 使用while语句向数据表中批量插入数据
- MySQL将查询结果插入到数据表中
- MySQL将查询结果插入到数据表中
- MySQL将查询结果插入到数据表中
- MySQL将查询结果插入到数据表中
- MySQL将查询结果插入到数据表中
- mysql将数据表插入到另一个数据库的表
- MySQL--数据表插入记录
- python读取txt并将数据插入到sql中
- 将数据表DataTable转为压缩JSON格式
- 用cxfreeze将python转为exe
- Python 将一个目录下的所有word文档转为txt
- 批量将txt文件转为csv文件
- 学习MySQL中遇到的问题(net start mysql; 服务名无效。 请键入 NET HELPMSG 2185 以获得更多的帮助)
- JS中的一些Function (前端 第六节)
- windows8下配置boost(python)
- opengles绘制跨平台UI系统结构图
- 截取字符串,含有汉字和字母,不能截半个汉字
- 用python将txt数据表转为mysql插入语句
- Unity3D ugui 界面状态控制
- 简易版WireShark实现-相关网络知识(3)
- python chr()、unichr()和ord()使用
- 1005. Spell It Right (20)
- webView项目总结(持续更新...)
- spring实战笔记2 spring mvc
- [Lesson2]Nuttx 源码编译
- C++友元类