Skip to content

Commit 9a03595

Browse files
committed
2 and 4 changes
1 parent 37a07f0 commit 9a03595

File tree

5 files changed

+209
-43
lines changed

5 files changed

+209
-43
lines changed

burness/0007/Program_lines_stat.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# 解决多行注释 如python中的'''
1515
multi_comment_start={'python':'\'\'\'','c':'/*'}
1616
multi_comment_end={'python':'\'\'\'','c':'*/'}
17-
1817
def stat_lines(file_name,file_type):
1918
import re
2019
is_comment=False
@@ -69,4 +68,4 @@ def main():
6968

7069

7170
if __name__=='__main__':
72-
main()
71+
main()

kamen/0002/gene_key_save_in_mysql.py

+26-41
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
'charset':'utf8'
1111
}
1212

13-
try:
14-
cnn=mysql.connector.connect(**config)
15-
except mysql.connector.Error as e:
16-
print ('connect fails!'.format(e))
1713

18-
print cnn
1914

2015
class sql_struct():
2116
def __init__(self,config):
@@ -25,25 +20,29 @@ def conn_sql(self):
2520
try:
2621
conn=mysql.connector.connect(**self.config)
2722
except mysql.connector.Error as e:
28-
print ('connect fails!'.format(e))
23+
print ('connect fails!{}'.format(e))
2924
self.conn=conn
3025

3126

3227
def conn_execute(self, sql_string, data):
3328
cursor=self.conn.cursor()
34-
cursor.execute(sql_string);
35-
# try:
36-
# if data is '':
37-
# cursor.execute(sql_string);
38-
# elif type(data) is tuple:
39-
# cursor.execute(sql_string, data);
40-
# elif type(data) is dict:
41-
# cursor.execute(sql_string, data)
42-
# except mysql.connector.Error as e:
43-
# print('fails{}'.format(e));
29+
#cursor.execute(sql_string);
30+
try:
31+
if data is '':
32+
cursor.execute(sql_string);
33+
elif type(data) is tuple:
34+
cursor.execute(sql_string, data);
35+
elif type(data) is dict:
36+
cursor.execute(sql_string, data)
37+
except mysql.connector.Error as e:
38+
print('fails{}'.format(e));
39+
4440
def sql_close(self):
4541
self.conn.close()
4642

43+
def sql_commit(self):
44+
self.conn.commit()
45+
4746
class gene_keys():
4847
def __init__(self,num):
4948
self.num = num;
@@ -60,39 +59,25 @@ def return_list(self):
6059
g=gene_keys(2);
6160
g.gene_list();
6261
keys_list=g.return_list();
63-
#db=sql_struct(config);
64-
#db.conn_sql();
65-
print cnn
62+
db=sql_struct(config);
63+
db.conn_sql();
64+
#print cnn
65+
6666
#sql create table ``
6767
sql_create_table='create table `keyss1` (\
6868
`source` varchar(10),\
6969
`key` varchar(20)\
7070
)';
7171

72-
#db.conn_execute(sql_create_table, '');
73-
cursor=cnn.cursor()
74-
sql_insert2="insert into keyss1 (source, key) values ('orange', '20')"
75-
cursor.execute(sql_insert2);
76-
#db.sql_close()
77-
#for key in keys_list:
78-
# data=('uuid', key);
79-
#print key
80-
#db.conn_execute(sql_insert2,'')
81-
# cursor=cnn.cursor()
82-
# cursor.execute(sql_insert2);
83-
#db.sql_close()
84-
85-
86-
72+
sql_insert2=("insert into keyss1(source, keyss) values (%s, %s)")
73+
for key in keys_list:
74+
data=('uuid', key);
75+
db.conn_execute(sql_insert2,data)
76+
77+
db.sql_commit();
78+
db.sql_close()
8779

8880

8981

9082

9183

92-
93-
#cursor=cnn.cursor()
94-
#print sql_create_table
95-
#try:
96-
# cursor.execute(sql_create_table)
97-
#except mysql.connector.Error as e:
98-
# print('create table fails'.format(e));

kamen/0004/a.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
A Counter is a dict subclass for counting hashable objects.
2+
It is an unordered collection where elements are stored as dictionary keys and their
3+
counts are stored as dictionary values. Counts are allowed to be any integer value including
4+
zero or negative counts. The Counter class is similar to bags or multisets in other languages

kamen/0004/word_count.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections import Counter
2+
#collections
3+
#counter + - & | most_common
4+
with open('a.txt', 'r') as f:
5+
c=Counter()
6+
for line in f:
7+
line_list=line.split()
8+
c+=Counter(line_list)
9+
10+
print c.most_common()
11+

kamen/README.md

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
## Python 练习册,每天一个小程序 ##
2+
3+
#### 说明: ####
4+
5+
- Python 练习册,每天一个小程序。注:将 Python 换成其他语言,大多数题目也试用`
6+
- 不会出现诸如「打印九九乘法表」、「打印水仙花」之类的题目
7+
- 欢迎大家 Pull Request 出题目,贴代码(Gist、Blog皆可):-)
8+
9+
> Talk is cheap. Show me the code.--Linus Torvalds
10+
11+
----------
12+
13+
**第 0000 题:**将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
14+
类似于图中效果
15+
16+
![头像](http://i.imgur.com/sg2dkuY.png?1)
17+
18+
**第 0001 题:**做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用**生成激活码**(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
19+
20+
**第 0002 题**:将 0001 题生成的 200 个激活码(或者优惠券)保存到 **MySQL** 关系型数据库中。
21+
22+
**第 0003 题:**将 0001 题生成的 200 个激活码(或者优惠券)保存到 **Redis** 非关系型数据库中。
23+
24+
**第 0004 题:**任一个英文的纯文本文件,统计其中的单词出现的个数。
25+
26+
**第 0005 题:**你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。
27+
28+
**第 0006 题:**你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都是英文,请统计出你认为每篇日记最重要的词。
29+
30+
**第 0007 题:**有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
31+
32+
**第 0008 题:**一个HTML文件,找出里面的**正文**
33+
34+
**第 0009 题:**一个HTML文件,找出里面的**链接**
35+
36+
**第 0010 题:**使用 Python 生成类似于下图中的**字母验证码图片**
37+
38+
![字母验证码](http://i.imgur.com/aVhbegV.jpg)
39+
40+
- [阅读资料](http://stackoverflow.com/questions/2823316/generate-a-random-letter-in-python)
41+
42+
**第 0011 题:** 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
43+
44+
北京
45+
程序员
46+
公务员
47+
领导
48+
牛比
49+
牛逼
50+
你娘
51+
你妈
52+
love
53+
sex
54+
jiangge
55+
56+
**第 0012 题:** 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。
57+
58+
**第 0013 题:** 用 Python 写一个爬图片的程序,爬 [这个链接里的日本妹子图片 :-)](http://tieba.baidu.com/p/2166231880)
59+
60+
- [参考代码](http://www.v2ex.com/t/61686 "参考代码")
61+
62+
**第 0014 题:** 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示:
63+
64+
{
65+
"1":["张三",150,120,100],
66+
"2":["李四",90,99,95],
67+
"3":["王五",60,66,68]
68+
}
69+
70+
请将上述内容写到 student.xls 文件中,如下图所示:
71+
72+
![student.xls](http://i.imgur.com/nPDlpme.jpg)
73+
74+
**第 0015 题:** 纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示:
75+
76+
{
77+
"1" : "上海",
78+
"2" : "北京",
79+
"3" : "成都"
80+
}
81+
82+
请将上述内容写到 city.xls 文件中,如下图所示:
83+
84+
![city.xls](http://i.imgur.com/rOHbUzg.png)
85+
86+
87+
**第 0016 题:** 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
88+
89+
[
90+
[1, 82, 65535],
91+
[20, 90, 13],
92+
[26, 809, 1024]
93+
]
94+
95+
请将上述内容写到 numbers.xls 文件中,如下图所示:
96+
97+
![numbers.xls](http://i.imgur.com/iuz0Pbv.png)
98+
99+
**第 0017 题:** 将 第 0014 题中的 student.xls 文件中的内容写到 student.xml 文件中,如
100+
101+
下所示:
102+
103+
<?xml version="1.0" encoding="UTF-8"?>
104+
<root>
105+
<students>
106+
<!--
107+
学生信息表
108+
"id" : [名字, 数学, 语文, 英文]
109+
-->
110+
{
111+
"1" : ["张三", 150, 120, 100],
112+
"2" : ["李四", 90, 99, 95],
113+
"3" : ["王五", 60, 66, 68]
114+
}
115+
</students>
116+
</root>
117+
118+
- [阅读资料](http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html) 腾讯游戏开发 xml 和 Excel 相互转换
119+
120+
**第 0018 题:** 将 第 0015 题中的 city.xls 文件中的内容写到 city.xml 文件中,如下所示:
121+
122+
<?xmlversion="1.0" encoding="UTF-8"?>
123+
<root>
124+
<citys>
125+
<!--
126+
城市信息
127+
-->
128+
{
129+
"1" : "上海",
130+
"2" : "北京",
131+
"3" : "成都"
132+
}
133+
</citys>
134+
</root>
135+
136+
**第 0019 题:** 将 第 0016 题中的 numbers.xls 文件中的内容写到 numbers.xml 文件中,如下
137+
138+
所示:
139+
140+
<?xml version="1.0" encoding="UTF-8"?>
141+
<root>
142+
<numbers>
143+
<!--
144+
数字信息
145+
-->
146+
147+
[
148+
[1, 82, 65535],
149+
[20, 90, 13],
150+
[26, 809, 1024]
151+
]
152+
153+
</numbers>
154+
</root>
155+
156+
**第 0020 题:** [登陆中国联通网上营业厅](http://iservice.10010.com/index_.html) 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。
157+
158+
**第 0021 题:** 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?请使用 Python 对密码加密。
159+
160+
- 阅读资料 [用户密码的存储与 Python 示例](http://zhuoqiang.me/password-storage-and-python-example.html)
161+
162+
- 阅读资料 [Hashing Strings with Python](http://www.pythoncentral.io/hashing-strings-with-python/)
163+
164+
- 阅读资料 [Python's safest method to store and retrieve passwords from a database](http://stackoverflow.com/questions/2572099/pythons-safest-method-to-store-and-retrieve-passwords-from-a-database)
165+
166+
167+

0 commit comments

Comments
 (0)