安ip.txt文件像这样的文件:192.168.49.132 test 1
192.168.49.133 test 2
现在我可以把它上传到我的django项目中
^{pr2}$
阅读列表并插入mysqldef mysql_insert(iplist,userlist,passwordlist):
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='123',port=3306)
cur =conn.cursor()
cur.execture('create database if not exists python')
conn.select_db('mmot')
for ip,user,password in zip(iplist,userlist,passwordlist):
cur.execture('insert into ip_iptable(ip,user,password) values(%s,%s,%s) ' %(ip,user,password))
cur.close()
conn.close()
except MySQLdb.Error,e:
print ('Some error!')
阅读文件并将它们存储在三个列表中def open_file(filename):
iplist=[]
userlist=[]
passwordlist=[]
try:
if str(filename).endswith('.txt'):</