1 #-*-coding:utf-8-*-
2 __author__ = 'Deen'
3 '''
4 题目描述:
5 将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。
6 '''
7 """
8 import MySQLdb as mdb
9
10 config = {
11 'host': '127.0.0.1',
12 'port': 3306,
13 'user': 'root',
14 'passwd': '',
15 'db': 'student',
16 'charset': 'utf8'
17 }
18 conn = mdb.connect(**config)
19 cursor = conn.cursor(cursorclass=mdb.cursors.DictCursor)
20
21
22
23 cursor.execute('set names gbk')
24
25
26
27 n=0
28 num=list()
29
30
31 for line in open("student12.txt"):
32 line=line.decode('gbk').encode('utf-8')
33
34 n=n+1
35
36 if n%6==1:
37 cursor.execute('insert into student12(sno) VALUES (%s)'%(line))
38
39 """
40
41 import MySQLdb as mdb
42
43 config = {
44 'host': '127.0.0.1',
45 'port': 3306,
46 'user': 'root',
47 'passwd': '',
48 'db': 'ctf_test',
49 'charset': 'utf8'
50 }
51 conn = mdb.connect(**config)
52 cursor = conn.cursor(cursorclass=mdb.cursors.DictCursor)
53 cursor.execute('set names gbk')
54
55 cursor.execute('create table codes(id int(5),code char(20))')
56 with open('poll_codes.txt','r') as fp:
57 for line in fp.readlines():
58 line = line.strip('\n').split(':')
59 cursor.execute('INSERT INTO codes VALUES (%s,%s)',line)
60
61
62 conn.commit()
63 cursor.close()
64 conn.close()

最新文章

  1. DBNEWNAME工具介绍
  2. java基础总结——基础语法1
  3. 配置Tomcat web保存文件到项目路径之外
  4. XCODE UITextField 中的属性和用法
  5. Dev-Cpp配置OpenGL图形库(成功版本:Dev-Cpp 5.7.1 MinGW 4.8.1)
  6. [转]IIS7.5 添加expires头 提高性能
  7. hazelcast的坑爹事
  8. JavaScript 公有 私有 静态属性和方法
  9. join函数——Gevent源码分析
  10. opencv2 矩阵方式 resize图像缩放代码(转载)
  11. mysql show命令
  12. go web 第一天 学习笔记
  13. 2015年CSDN博客排名第一名,何方神圣?
  14. 深度链接(DeepLinking)怎样免费实现
  15. SCOI2019酱油记
  16. jquery第二篇
  17. PHP计算连续签到天数以及累计签到天数
  18. linux 下crontab -e 命令插入及保存
  19. Python数据挖掘和机器学习
  20. Codeforces 873F Forbidden Indices 字符串 SAM/(SA+单调栈)

热门文章

  1. spring boot 配置静态路径
  2. c语言数据结构,你可能还不知道的顺序表
  3. 如何在 Xamarin 中快速集成 Android 版认证服务 - 邮箱地址篇
  4. spring IOC的理解,原理与底层实现?
  5. 【axios三部曲】一、使用axios
  6. 太骚了,用Excel玩机器学习
  7. 【C#】通过一个案例 彻底了解 Volatile和 内存屏障
  8. 【C#反射】BindingFlags 枚举
  9. 微服务从代码到k8s部署应有尽有系列(九、事务精讲)
  10. javaScript(js)手写原生任务定时器源码