How to put semicolon in value in python configurator?
I need to provide the password on the right side of the equal sign in the python configparser file, but the semicolon is a comment character.
Escape from \ doesn't work.
How to pass the string "foo;" how is the value in configparser?
+2
dmd
source
to share
3 answers
A short interactive session shows the semicolon is readable without issue.
>>> import StringIO
>>> import ConfigParser
>>> f = StringIO.StringIO("[sec1]\npwd=foo;\n")
>>> p = ConfigParser.ConfigParser()
>>> p.readfp(f)
>>> p.items('sec1')
[('pwd', 'foo;')]
>>>
+1
gimel
source
to share
Mine works great. And noticed "Lines start with '#' or ';' are ignored and can be used to provide comments. "
+1
Kabie
source
to share
ConfigParser has an error with spaces before semicolons:
>>> import StringIO
>>> import ConfigParser
>> p = ConfigParser.ConfigParser()
>>> s1 = StringIO.StringIO('[foo]\nbla=bar;baz\n')
>>> p.readfp(s1)
>>> p.items('foo')
[('bla', 'bar;baz')]
>>> s2 = StringIO.StringIO('[foo]\nbla=bar ;-) baz\n')
>>> p.readfp(s2)
>>> p.items('foo')
[('bla', 'bar')]
>>> s3 = StringIO.StringIO('[foo]\nbla=bar \;-) baz\n')
>>> p.readfp(s3)
>>> p.items('foo')
[('bla', 'bar \\;-) baz')]
>>>
Note that the latest version is still wrong because the backslash stays there ...
+1
Hauke ββRehfeld
source
to share