Urllib.urlencode question?

Konstantin Veretennicov kveretennicov at yahoo.com
Wed May 12 11:32:17 EDT 2004


"Sean Berry" <sean_berry at cox.net> wrote in message news:<p%hoc.113536$Jy3.54431 at fed1read03>...
> the desired result will be in the form
> 
> n=2&userid0=sean&username0=Sean%20Berry&email0=sean_berry%40cox.net&userid1=
> pam&username1=Pam%20Ward&email1=pam_ward%40cox.net
> 
> How can achieve adding the numbers to the end of the variable names so that
> they can be used by Flash's loadVars function.
> 

I don't know anything about Flash loadVars, but how about this:

fields = ['userid', 'username', 'email']
users = [
    ['sean', 'Sean Berry', 'sean_berry at cox.net'],
    ['pam', 'Pam Ward', 'pam_ward at cox.net']
    ]

pairs = [('n', len(users))]
for i, u in enumerate(users):
    numbered_fields = [f + str(i) for f in fields]
    pairs += zip(numbered_fields, u)
    
import urllib
print urllib.urlencode(pairs)


- kv



More information about the Python-list mailing list