Urllib.urlencode question?

Sean Berry sean_berry at cox.net
Wed May 12 13:32:38 EDT 2004


Thank you very much.   That is exactly what I was looking for.  I need to
start using enumerate... it is a good one.


"Konstantin Veretennicov" <kveretennicov at yahoo.com> wrote in message
news:5155aad2.0405120732.646a98d4 at posting.google.com...
> "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