import os import configparser proDir = os.path.split(os.path.realpath(__file__))[0] configPath = os.path.join(proDir, "xs.ini") class ReadConfig(): def __init__(self): self.parse = configparser.ConfigParser() proDir = os.path.split(os.path.realpath(__file__))[0] configPath = os.path.join(proDir, "xs.ini") self.parse.read(configPath) def get_email_qq_qq(self): value = self.parse['email_qq']['qq'] return value def get_email_qq_mm(self): value = self.parse['email_qq']['mm'] return value if __name__ == "__main__": cs = ReadConfig() print(cs.get_email_qq_qq()) print(cs.get_email_qq_mm())
[email_qq]
qq=123456
mm=1sstt
;
[mima]
#r=123
r=12345
t=www.baidu.com
执行结果:
注意:
import os
proDir = os.path.split(os.path.realpath(__file__))[0]
print(proDir)
#执行结果: C:UsersdelPycharmProjectsuntitled1cs
configPath = os.path.join(proDir, "xs.ini")
print(configPath)
#执行结果:C:UsersdelPycharmProjectsuntitled1csxs.ini
"""
proDir = os.path.split(os.path.realpath(__file__))[0]
print(proDir)
#执行结果: C:UsersdelPycharmProjectsuntitled1cs
------------
configPath = os.path.join(proDir, "xs.ini")
print(configPath)
#执行结果:C:UsersdelPycharmProjectsuntitled1csxs.ini
"""