File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ # -*- coding:utf-8 -*-
3+
4+ #####################################
5+ ######### 剔除'#'开头的注释 #########
6+ #####################################
7+
8+ import re
9+
10+ def main ():
11+ if __name__ == "__main__" :
12+
13+ #################
14+ # Get file path #
15+ #################
16+ file_p = input ("Please enter file path:" )
17+
18+ #######################
19+ # Get the point index #
20+ #######################
21+ i = file_p .index ('.' )
22+
23+ ##################################
24+ # Get the file reader and writer #
25+ ##################################
26+ reader = open (file_p , "r" )
27+ writer = open (file_p [:i ] + '[no-notes]' + file_p [i :], "w" )
28+
29+ #########################
30+ # Delete the letter '#' #
31+ #########################
32+ while True :
33+ line = reader .readline ()
34+ if not len (line ):
35+ reader .close ()
36+ writer .close ()
37+ break
38+ line = re .sub (r"^\s*#.*\n$" , lambda match_obj :None , line )
39+ writer .write (line )
40+
41+ main ()
42+
43+
You can’t perform that action at this time.
0 commit comments