Python concepts
Read and write to the ini file:
ontents in my backup_settings.ini file
[Settings]
year = 2020
python code for reading
import configparser
config = configparser.ConfigParser()
config.read('backup_settings.ini') #path of your .ini file
year = config.get("Settings","year")
print(year)
for writing or updating
from pathlib import Path
import configparser
myfile = Path('backup_settings.ini') #Path of your .ini file
config.read(myfile)
config.set('Settings', 'year','2050') #Updating existing entry
config.set('Settings', 'day','sunday') #Writing new entry
config.write(myfile.open("w"))
output
[Settings]
year = 2050
day = sunday2. Glob module: blog
3. Pathlib module: blog
4. read and writoing contentsto ini file(2 ways using modules):
i)config parser(here or here)(basic)
ii)config updater(here)(advanced)
ocnfig updater package: here
Comments
Post a Comment