Is urllib.urlencode() not enough?
>>> import urllib
>>> urllib.urlencode({'foo': 'bar', 'bla': 'blah'})
foo=bar&bla=blah
EDIT:
You can also update the existing url:
>>> import urlparse, urlencode
>>> url_dict = urlparse.parse_qs('a=b&c=d')
>>> url_dict
{'a': ['b'], 'c': ['d']}
>>> url_dict['a'].append('x')
>>> url_dict
{'a': ['b', 'x'], 'c': ['d']}
>>> urllib.urlencode(url_dict, True)
'a=b&a=x&c=d'
Note that parse_qs
function was in cgi
package before Python 2.6
EDIT 23/04/2012:
You can also take a look at python-requests - it should kill urllibs eventually :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…