1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import configparser
config = configparser.ConfigParser() config.read("MysqlConfig.ini", encoding="utf-8")
dev_section = "dev" dev_option = ["url", "username", "password"] dev_url = "jdbc:mysql://localhost:3306/dev1" dev_username = "dev1" dev_password = "dev11"
if not config.has_section(dev_section): config.add_section(dev_section)
if not config.has_option(dev_section, dev_option[0]): config.set(dev_section, dev_option[0], dev_url)
if not config.has_option(dev_section, dev_option[1]): config.set(dev_section, dev_option[1], dev_username)
if not config.has_option(dev_section, dev_option[2]): config.set(dev_section, dev_option[2], dev_password)
config.set(dev_section, dev_option[2], "update_dev")
config.write(open("MysqlConfig.ini", "w"))
|