本文介绍了用引号拆分参数行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好, 首先我是蟒蛇的新手(但我在互联网上搜索我发誓)。 我正在寻找一些将字符串拆分为一对列表的方法 ''key = value''。这段代码应该能够处理这个特殊的 示例字符串: qop =" auth,auth-int,auth-conf",cipher =" ; rc4-40,rc4-56,rc4,des, 3des",maxbuf = 1024,charset = utf-8,algorithm = md5-sess $ b $我知道我可以用一些正则表达式来做到这一点(我现在正在努力学习 那个)但是如果有其他的方式... 谢谢 解决方案 这是非常规的,使用eval也不是安全的。 [(''algorithm'',''md5-sess''),(''maxbuf'',1024),(''charset'',''utf-8''), (''cipher'',''rc4-40,rc4-56,rc4,des,3des''),(''qop'',''auth,auth-int,auth- conf'')] .... algorithm = md5-sess maxbuf = 1024 charset = utf-8 cipher = rc4-40,rc4-56,rc4,des,3des qop = auth,auth-int,auth-conf 为了安全评估,请参阅 http://aspn.activestate.com/ ASPN / Coo ... / Recipe / 364469 -N 看一下shlex模块。你或许可以摆弄shlex 对象并说服它在逗号上拆分。但是,说实话,如果分界逗号是空格,那么 将会更容易解析 而不是。 j 首先我是python的新手(但是我发誓在互联网上搜索)。 我正在寻找一些分裂字符串的方法成对的列表 ''key = value''。这段代码应该能够处理这个特殊的 示例字符串: 这是非常规的,使用eval是也不是SAFE。>> s =''qop =" auth,auth-int,auth-conf",cipher =" rc4-40,rc4-56,rc4,des,3des",maxbuf = 1024, charset =" utf-8",algorithm =" md5-sess"'' 谢谢你。问题是我没有charset =" utf-8"但是 charset = utf-8。有时候有时不! Hello, first i''m a newbie to python (but i searched the Internet i swear).i''m looking for some way to split up a string into a list of pairs''key=value''. This code should be able to handle this particularexample string : qop="auth,auth-int,auth-conf",cipher="rc4-40,rc4-56,rc4,des,3des",maxbuf=1024,charset=utf-8,algorithm=md5-sess i know i can do that with some regexp (i''m currently trying to learnthat) but if there''s some other way... thanks 解决方案 This is unconventional and using eval is not SAFE too. [(''algorithm'', ''md5-sess''), (''maxbuf'', 1024), (''charset'', ''utf-8''),(''cipher'', ''rc4-40,rc4-56,rc4,des,3des''), (''qop'', ''auth,auth-int,auth-conf'')] ....algorithm = md5-sessmaxbuf = 1024charset = utf-8cipher = rc4-40,rc4-56,rc4,des,3desqop = auth,auth-int,auth-conf For safe eval, take a look at http://aspn.activestate.com/ASPN/Coo.../Recipe/364469 -NTake a look at the shlex module. You might be able to fiddle with the shlexobject and convince it to split on the commas. But, to be honest, thatabove would be a lot easier to parse if the dividing commas were spacesinstead. j This is unconventional and using eval is not SAFE too.>>s = ''qop="auth,auth-int,auth-conf",cipher="rc4-40,rc4-56,rc4,des,3des",maxbuf=1024,charset="utf-8",algorithm="md5-sess"'' thanks for that. The problem is i don''t have charset="utf-8" butcharset=utf-8. Sometimes " sometimes not! 这篇关于用引号拆分参数行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 16:32