233123 发表于 2016-5-19 09:10:01

python中去掉文件的注释

import sys
import re
PY_PATTERN = re.compile(
    r"""
   \s*\#(?:[^\r\n])*
   | \s*__(?:[^\r\n]*)
   | "{3}(?:\\.|[^\\])*"{3}
   | '{3}(?:\\.|[^\\])*'{3}
   """,
    re.VERBOSE | re.MULTILINE | re.DOTALL
)

txt = open("cmd.txt").readlines()
b = re.sub(PY_PATTERN,'', ''.join(txt))
single = re.compile(r"\n\n")
b = re.sub(single,'\n',b)
print(b)

项籍字羽 发表于 2016-5-20 14:09:43

之前在云主机部署过,但是使用起来还是不熟悉 刚好这本书看看
页: [1]
查看完整版本: python中去掉文件的注释