标签:nal finally 脚本 去除 main pytho str ring usr
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# python 3.4
import re
import sys
def main(argv):
rf = open(argv[0],‘rU‘,encoding=‘UTF-8‘)
outstring = ‘‘
try:
outstring = rf.read()
finally:
rf.close()
m = re.compile(r‘#.*‘)
outtmp = re.sub(m,‘‘,outstring)
outstring = outtmp
outtmp = re.sub(r‘^\n|\n+(?=\n)|\n$‘,‘‘,outstring)
outstring = outtmp
print(argv[0], argv[1])
f = open(argv[1], ‘w‘)
f.write(outstring)
f.close()
if __name__ == "__main__":
main(sys.argv[1:])
标签:nal finally 脚本 去除 main pytho str ring usr
原文地址:https://blog.51cto.com/sgk2011/2429974