Skip to content

Commit f9d3a51

Browse files
committed
add 0007
1 parent 283115a commit f9d3a51

File tree

6 files changed

+141
-1
lines changed

6 files changed

+141
-1
lines changed

Matafight/0007/countCodeLines.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#_*_ encoding: utf-8 _*_
2+
import os
3+
import re
4+
#http://www.cnblogs.com/zhoujie/archive/2013/04/10/python7.html
5+
#http://cuiqingcai.com/977.html
6+
class countLines:
7+
def __init__(self):
8+
self.comment=0;
9+
self.codes=0;
10+
self.blank=0;
11+
self.fileList=[];#存的是各个文件相关的list
12+
def openDir(self,dirname):
13+
curdir=os.getcwd();
14+
curdir=curdir+str(dirname);
15+
print curdir
16+
dirlist=os.listdir(curdir);
17+
checkpy=re.compile(r"\.py$");
18+
for item in dirlist:
19+
if checkpy.search(item):
20+
item="\\"+item;
21+
self.count(curdir+item);
22+
23+
def count(self,filename):
24+
self.comment=0;
25+
self.codes=0;
26+
self.blank=0;
27+
f=file(filename,'r');
28+
patcomment=re.compile(r"^\s*#");#
29+
patblank=re.compile(r"^\s+$");#空白字符
30+
for line in f.readlines():
31+
if patblank.search(line):
32+
self.blank+=1;
33+
elif patcomment.search(line):
34+
self.comment+=1;
35+
else:
36+
self.codes+=1;
37+
self.fileList.append([filename,self.codes,self.comment,self.blank]);
38+
39+
f.close();
40+
41+
def getResult(self):
42+
return self.fileList;
43+
44+
if __name__=="__main__":
45+
countInstance=countLines();
46+
countInstance.openDir(r"\testDir");
47+
relist=countInstance.getResult();
48+
for item in relist:
49+
print item[0];
50+
print "code num:"+str(item[1]);
51+
print "comment num:"+str(item[2]);
52+
print "blank num:"+str(item[3]);
53+
print "\n"
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+

Matafight/0007/testDir/countWord.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#_*_ encoding: utf-8 _*_
2+
import re
3+
4+
inputfile=file("test.txt",'r');
5+
count=0;
6+
for line in inputfile.readlines():
7+
word=re.findall(r"\w+",line);
8+
count+=len(word);
9+
print "total wordcount is "+ str(count);
10+
inputfile.close();
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#_*_ encoding: utf-8 _*_
2+
import uuid
3+
4+
class generate:
5+
def __init__(self):
6+
self.num=0;
7+
self.listid=[];
8+
def generate_uuid(self,num):
9+
for i in range(int(num)):
10+
self.listid.append(uuid.uuid1());
11+
12+
def get_uuid(self):
13+
return self.listid;
14+
15+
if __name__=="__main__":
16+
gencode=generate();
17+
gencode.generate_uuid(200);
18+
keys=gencode.get_uuid();
19+
filekeys=file("gencodes.txt",'w');
20+
for key in keys:
21+
filekeys.write(str(key)+'\n');
22+
filekeys.close();
23+
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#_*_ encoding: utf-8 _*_
2+
import re
3+
4+
class countWord:
5+
def __init__(self):
6+
self.dic={};
7+
self.word="";
8+
9+
10+
def count(self,filename):
11+
self.dic={};
12+
fopen=file(filename,'r');
13+
for lines in fopen.readlines():
14+
words=re.findall(r"\w+",lines);
15+
for items in words:
16+
if items in self.dic.keys():
17+
self.dic[items]+=1;
18+
else:
19+
self.dic[items]=1;
20+
21+
#对字典value值排序
22+
dict= sorted(self.dic.iteritems(), key=lambda d:d[1], reverse = True);
23+
self.word=dict[0][0];
24+
25+
def getWord(self):
26+
return self.word;
27+
28+
29+
if __name__=="__main__":
30+
diarycount=countWord();
31+
order=1;
32+
importantlist=[];
33+
for order in range(1,4):
34+
fname="diary"+str(order)+".txt";
35+
diarycount.count(fname);
36+
importantlist.append(diarycount.getWord());
37+
order+=1;
38+
for item in importantlist:
39+
print str(item)+"\t";
40+
41+

Matafight/0007/testDir/test.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
what
2+
#
3+
kiddingme

acwong00/0000/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
d = ImageDraw.Draw(original)
88

9-
d.text((200, 0), "7", font=fnt, fill=(255,0,0,255))
9+
d.text((200, 0), "6", font=fnt, fill=(255,0,0,255))
1010

1111
original.save("finnal.jpg")

0 commit comments

Comments
 (0)