python 實現過慮配置文件去掉 #號行

以下是實現代碼,不過,大家可以使用shell去實現很簡單

[root@localhost conf]# cat r.py

import sys

import re

file=open('httpd.conf')

try:

all_file=file.read()

pattern = re.compile('(^[^#|\n]+)', re.M)

result = pattern.findall(all_file)

for x in result:

print x

finally:

file.close()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章