How do I put a semicolon in a value in python configparser?的Python ConfigParser与结肠癌的关键
的Python - 2.7
我有一个部分,其中的关键是URL和值是一个令牌的蟒蛇配置解析器。关键是一个url包含:, - ,?和其他各种字符同样适用于价值。从上面的问题可以看出,value部分中的特殊字符似乎没有问题,但关键看起来并不好。
我能做些什么吗?我的选择是解决一个JSON文件,并手动手动写/读。
例如,如果您运行下面的程序,一旦我得到
cp = ConfigParser.ConfigParser()
cp.add_section("section")
cp.set("section", "http://myhost.com:9090", "user:id:token")
cp.set("section", "key2", "value2")
with open(os.path.expanduser("~/test.ini"), "w") as f:
cp.write(f)
cp = ConfigParser.ConfigParser()
cp.read(os.path.expanduser("~/test.ini"))
print cp.get("section", "key2")
print cp.get("section", "http://myhost.com:9090")
文件看起来像下面
[section]
http://myhost.com:9090 = user:id:token
key2 = value2
而且我得到异常ConfigParser.NoOptionError: No option 'http://myhost.com:9090' in section: 'section'