File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import os
2+ from os .path import join
3+ import re
4+
5+
6+ def count_words (root ):
7+ wdic = {}
8+ for root , dirs , files in os .walk (root ):
9+ for name in files :
10+ filename = join (root , name )
11+
12+ f = open (filename , 'rb' )
13+ for line in f :
14+ line = line .lower ().strip ()
15+ words = re .findall ('[a-zA-Z0-9]+' , line )
16+ for word in words :
17+ if word in wdic :
18+ wdic [word ] += 1
19+ else :
20+ wdic [word ] = 1
21+ f .close ()
22+ wdic = sorted (wdic .items (), key = lambda x : x [1 ], reverse = True )
23+ print wdic
24+
25+ if __name__ == '__main__' :
26+ root = 'test'
27+ count_words (root )
Original file line number Diff line number Diff line change 1+ one one one
2+ two two
3+ five
Original file line number Diff line number Diff line change 1+ five
2+ five
3+ five
4+ five
Original file line number Diff line number Diff line change 1+ import os
2+ from os .path import join
3+ import re
4+
5+ comm = '[(#)(//)(/*)(*)]'
6+ prog = re .compile (comm )
7+
8+ def count_line (root ):
9+ codecount = 0
10+ emptycount = 0
11+ commcount = 0
12+ for root , dirs , files in os .walk (root ):
13+ for name in files :
14+ filename = join (root , name )
15+ f = open (filename )
16+ for line in f :
17+ if line .strip () == '' :
18+ emptycount += 1
19+ #python script
20+ elif prog .match (line .strip ()) != None :
21+ commcount += 1
22+ else :
23+ codecount += 1
24+ f .close ()
25+
26+ print 'code lines: ' , codecount
27+ print 'comment lines: ' , commcount
28+ print 'empty lines: ' , emptycount
29+
30+ if __name__ == '__main__' :
31+ root = 'test'
32+ count_line (root )
Original file line number Diff line number Diff line change 1+ public class Test {
2+ public static void main (String [] args ) {
3+ //print hello world
4+ /**
5+ *
6+ */
7+ System .out .println ("Hello World!" );
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ import socket
2+ import SocketServer as socketserver
3+ import select
4+ REMOTE_SERVER = '127.0.0.1'
5+ REMOTE_PORT = 9999
6+ LOCAL_SERVER = '127.0.0.1'
7+ LOCAL_PORT = 10001
8+ PORT = 10000
9+ BUFFER = 4096
10+ #Hello
11+ if __name__ == '__main__' :
12+ main ()
You can’t perform that action at this time.
0 commit comments