instead of writing the file like you do, look at configparser module from standard library. Your code will be way more clean and readable
Also I don't know if MariaDB python connector supports DictCursor like MySQL connector, but if it does - you can use it.
import configparser my_config="""[options] verbose = 1 read_all = false delete = true received = false delivered_to = false message_log = /home/mail/log message_log_verbose = true [destination] type = MDA_external path = /usr/bin/exim arguments = ("-i", "-bm", "user@localhost") unixfrom = true""" config = configparser.ConfigParser() config.read_string(my_config) cur = conn.cursor() query = "SELECT user, passwd, server FROM pop" cur.execute(query) for idx, row in enumerate(cur, start=1): credentials = dict(zip(('username', 'password', 'server'), row)) config['options'].update(credentials) with open(f'mail{idx}', 'w') as f: config.write(f)instead of string
my_config
can be a dict
Also I don't know if MariaDB python connector supports DictCursor like MySQL connector, but if it does - you can use it.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs