简体   繁体   中英

Align values in an INI file generated using ConfigParser

Below is the INI file i am generating using the ConfigParser:

[Global]
no_of_games =
superconf =

I am trying to generate an INI file with the "=" aligned uniformly as below, how could i achieve this, is there a way in the config parser to align the "=" at same position for all records ?

[Global]
no_of_games   =
superconf     =

You can use format to design a converter to save another ini file. But I think it's not a good idea.

Such like:

text = row
if row.find('=') > 0:
    data = row.split('=')
    var, val = data[0], data[1]
    text = "{0:<15} = {1:<15}\n".format(var, val.strip())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM