how to save = charactor in ini or cfg docement?

41 Views Asked by At

i want to save magnet link in ini document.Thus,it's inevitable that i have to save "=" charactor in the file.However,python deem "=" charactor a "option to value" ,so python idle returns"configparser.DuplicateOptionError: While reading from 'history.ini' [line 3]: option 'magnet' in section '0' already exists" when i use

configparser.ConfigParser().read('history.ini')

If you have any idea to deal with this problem ,please let me know, thanks in advance.

1

There are 1 best solutions below

1
On

I cannot reproduce the problem. I can save values containing = characters just fine:

test.ini

[Section]
Key=Val=ue

test.py

import configparser
cp = configparser.ConfigParser()
cp.read('ini.ini')
print(cp['Section']['Key'])  # Val=ue

I think the actual issue is just that you use the magnet key twice in the config (two lines which both start with magnet=).

If you want to have a list of multiple magnet links you can try using something like magnet00000=, magnet00001=, magnet00002=, and so on. Or switch to JSON.