Pergunta

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     =
Foi útil?

Solução

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())
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top