自己写的python脚本,抄的别人的,自己改了改,用于整理大量txt数据并插入到数据库

昨天,遇到了一个问题,有100w条弱口令数据,需要插入到数据库中,而且保存格式为txt。

身为程序员不可能一条一条的去写sql语句吧(主要是工作量太大,我也懒得干)。所以,我

就百度了一下,看有没有相似的脚本,可以用来拆拆改改的,本宝宝手气不错,找到了,代

码如下,防止以后会忘记,或者找不到,就写个随笔吧。

数据文件名称为easypwd.txt,目的是把每行数据都变成sql语句。

#coding:utf-8

import os

fileRead = open("C:/Users/Administrator/Desktop/easypwd.txt")

fileWrite = open("C:/Users/Administrator/Desktop/result.txt")

while ('' != content) :

string = 'INSERT INTO 'easypwd' VALUES (NULL,\''+content+'\');'

fileWrite.write(string)

content = fileRead.readline()

fileRead.close()

fileWrite.close()