处理连接字符串的工具
pyconstring的Python项目详细描述
pyconstring
处理连接字符串的工具。提供一个简单的api来解析和构造连接字符串 以Key=Value;的形式,就像处理字典一样简单。适用于Python2.7和3.x
许可证
麻省理工学院。见License File。
安装
pyconstring在pypi上
pip install pyconstring
或
easy_install pyconstring
用法示例
从头开始构造连接字符串:
>>>frompyconstringimportConnectionString>>>cs=ConnectionString()>>>cs['user']='manuel'>>>cs['password']='1234'>>>printcs.get_string()User=manuel;Password=1234;
解析已经存在的字符串:
>>>cs=ConnectionString.from_string('key1=value1;key2=value2;')>>>cs['key1']='another value'>>>cs.get_string()u'Key1=another value;Key2=value2;'>>>cs['user']='johnny'>>>printcs.get_string()Key1=anothervalue;Key2=value2;User=johnny;
必要时自动转义:
>>>cs=ConnectionString()>>>cs['weird=key']='" weird;value '>>>printcs.get_string()Weird==Key='" weird;value ';
按键翻译:
>>>cs['key']='value'>>>cs.translate({'key':'clave'})>>>printcs.get_string()Clave=value;
更多信息请参见documentation。
如果您发现任何bug或有任何建议,请随时给我发送电子邮件或在github上打开一个问题。