All pastes #2151 Raw Edit

jeff2 urlencode with multiple values

public python v1 · immutable
#2151 ·published 2004-11-17 18:32 UTC
rendered paste body
import typesimport urllibdef urlencode2(d):    a = []    for k in d:        v = d[k]        if type(v) == types.ListType:            for x in v:                a.append(urllib.urlencode({k: x}))        else:            a.append(urllib.urlencode({k: v}))    return "&".join(a)print urlencode2({"a": ["b", "c"]})# Output: a=b&a=cprint urllib.urlencode({"a": ["b", "c"]})# Output: wrong