Skip to content

Commit c5277f6

Browse files
author
yincongxian
committed
0004
1 parent 78ac900 commit c5277f6

6 files changed

Lines changed: 83 additions & 13 deletions

File tree

renzongxian/0000/0000.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from PIL import Image, ImageDraw, ImageFont
1313
import sys
1414

15+
1516
def add_num_to_img(file_path):
1617
im = Image.open(file_path)
1718
im_draw = ImageDraw.Draw(im)
@@ -21,8 +22,13 @@ def add_num_to_img(file_path):
2122
im.save(file_path)
2223

2324
if __name__ == "__main__":
24-
for infile in sys.argv[1:]:
25-
try:
26-
add_num_to_img(infile)
27-
except IOError:
28-
pass
25+
if len(sys.argv) <= 1:
26+
print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
27+
else:
28+
for infile in sys.argv[1:]:
29+
try:
30+
add_num_to_img(infile)
31+
print("Success!")
32+
except IOError:
33+
print("Can't open image!")
34+
pass

renzongxian/0000/image.png

36.4 KB
Loading

renzongxian/0002/0002.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Python 2.7, MySQL-python does not currently support Python 3
66

77
"""
8+
89
将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。
910
1011
"""
@@ -22,32 +23,32 @@ def generate_key():
2223

2324

2425
def write_to_mysql(key_list):
25-
# 打开数据库连接
26+
# Connect to database
2627
db = MySQLdb.connect("localhost", "test", "test1234", "testDB")
2728

28-
# 使用cursor()方法打开操作游标
29+
# Use function cursor() to open the cursor operation
2930
cursor = db.cursor()
3031

31-
# 如果数据表已存在,删除表
32+
# If the table exists, delete it
3233
cursor.execute("drop table if exists ukey")
3334

34-
# 创建数据表SQL语句
35+
# Create table
3536
sql = """create table ukey (
3637
key_value char(40) not null
3738
)"""
3839
cursor.execute(sql)
3940

40-
# SQL 插入
41+
# Insert data
4142
try:
4243
for i in range(200):
4344
cursor.execute('insert into ukey values("%s")' % (key_list[i]))
44-
# 提交到数据库执行
45+
# Commit to database
4546
db.commit()
4647
except:
47-
# 发生错误时回滚
48+
# Rollback when errors occur
4849
db.rollback()
4950

50-
# 关闭数据库
51+
# Close database
5152
db.close()
5253

5354

renzongxian/0003/0003.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Python 2.7
66

77
"""
8+
89
将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
910
1011
"""

renzongxian/0004/0004.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-12-07
4+
# Python 3.4
5+
6+
"""
7+
8+
任一个英文的纯文本文件,统计其中的单词出现的个数。
9+
10+
"""
11+
12+
import sys
13+
14+
15+
def word_count(file_path):
16+
file_object = open(file_path, 'r')
17+
18+
word_num = 0
19+
for line in file_object:
20+
line_list = line.split()
21+
word_num += len(line_list)
22+
23+
file_object.close()
24+
return word_num
25+
26+
if __name__ == "__main__":
27+
if len(sys.argv) <= 1:
28+
print("Need at least 1 parameter. Try to execute 'python 0004.py $image_path'")
29+
else:
30+
for infile in sys.argv[1:]:
31+
try:
32+
print("The total number of words is ", word_count(infile))
33+
except IOError:
34+
print("Can't open file!")
35+
pass

renzongxian/0004/test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Why are my contributions not showing up on my profile?
2+
Your profile contributions graph is a record of contributions you've made to GitHub repositories. Contributions are only counted if they meet certain criteria. In some cases, we may need to rebuild your graph in order for contributions to appear.
3+
4+
Contributions that are counted
5+
6+
Issues and pull requests
7+
8+
Issues and pull requests will appear on your contributions graph if they meet both of these conditions:
9+
10+
They were opened within the past year.
11+
They were opened in a standalone repository, not a fork.
12+
Commits
13+
14+
Commits will appear on your contributions graph if they meet all of the following conditions:
15+
16+
The commits were made within the past year.
17+
The email address used for the commits is associated with your GitHub account.
18+
The commits were made in a standalone repository, not a fork.
19+
The commits were made:
20+
In the repository's default branch (usually master)
21+
In the gh-pages branch (for repositories with Project Pages sites)
22+
In addition, at least one of the following must be true:
23+
24+
You are a collaborator on the repository or are a member of the organization that owns the repository.
25+
You have forked the repository.
26+
You have opened a pull request or issue in the repository.
27+
You have starred the repository.

0 commit comments

Comments
 (0)