pyqt-todolist/utils/ReadConfig.py
2022-04-17 17:25:35 +08:00

31 lines
No EOL
685 B
Python

import configparser
cfg_data = '''
[info]
users_dir= /home
name= $USER
home_dir= %(users_dir)s/%(name)s
'''
config = configparser.ConfigParser()
config.read_string(cfg_data)
users_dir = config['info']['users_dir']
name = config['info']['name']
home_dir = config['info']['home_dir']
print(users_dir)
print(name)
print(home_dir)
with open('test.ini', 'w') as config_file:
config.write(config_file)
config.add_section('Accounts')
config['Accounts']['baseUrl'] = 'https://cloud.liyp.cc'
config['Accounts']['name'] = 'admin'
config['Accounts']['type'] = 'NextCloud'
config['Accounts']['username'] = 'admin'
with open('test.ini', 'w') as config_file:
config.write(config_file)