读取coremail邮件系统的配置文件


 

#!/usr/bin/python
import configparser
import sys
f = configparser.ConfigParser(allow_no_value=True, strict=False)
configure_file = sys.argv[1]
f.read(configure_file, encoding="utf-8")

def query_section(input_section):
        if f.has_section(input_section):
            print('-->\033[31;1m%s\033[0m' % input_section)
            for has_section_line in f.options(input_section):
                print(has_section_line + " = " + f.get(input_section, has_section_line))

print("Press 'q' exit.")
while True:
    print("\nPrint all section:")
    print(f.sections())
    input_section = input("Please input section query: ")
    if input_section == 'q' or input_section == 'Q':
        break
    query_section(input_section)

./query_section_configure.py /home/coremail/conf/hosts.cf


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM