How to stop Python parse_qs from parsing single values into lists?

前端 未结 2 685
予麋鹿
予麋鹿 2020-12-28 12:15

In python 2.6, the following code:

import urlparse
qsdata = \"test=test&test2=test2&test2=test3\"
qs = urlparse.parse_qs(qsdata)
print qs
         


        
2条回答
  •  醉话见心
    2020-12-28 12:49

    A sidenote for someone just wanting a simple dictionary and never needing multiple values with the same key, try:

    dict(urlparse.parse_qsl('foo=bar&baz=qux'))
    

    This will give you a nice {'foo': 'bar', 'baz': 'qux'}. Please note that if there are multiple values for the same key, you'll only get the last one.

提交回复
热议问题