2

I have string like

s='www.gmail.com?uname=mark&pwd=test&age=20'

and i want string(s) to be converted into dict(d) in following manner

d={'uname':'mark','pwd':'test','age':20}

Thanks a lot

1
  • Show us what you tried. Commented Oct 4, 2013 at 12:32

1 Answer 1

12

BTW fix your URL. But here is the answer:

>>> from urlparse import urlparse, parse_qs
>>> url = 'www.gmail.com?uname=mark&pwd=test&age=20'
>>> urlparse(url).query
'uname=mark&pwd=test&age=20'
>>> parse_qs(urlparse(url).query)
{'age': ['20'], 'pwd': ['test'], 'uname': ['mark']}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.