By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,655 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

Urllib.urlencode question?

P: n/a
I have two lists... one like the following,

list1 ... ['userid', 'username', 'email']

and the other like this,

list2 ... [['sean', 'Sean Berry', 's*********@cox.net'], ['pam', 'Pam Ward',
'p*******@cox.net']]

Both lists are much more extensive, the first being a list of about 10
strings, and the second being a list of 20 lists each containing the values
corresponding to the first lists 10 strings. But, in order to simplify an
explanation I will use the previously described lists for my question.
I am going to pass this info to Flash in a url encoded string. I can do
this by parsing through the lists in list2 and appending a string to another
global string, then print this final string. But I run into problems
because the characters like '@', ' ', and '*' are not encoded. I have been
experimenting with urllib.urlencode and zipping the two lists together. But
the desired result will be in the form

n=2&userid0=sean&username0=Sean%20Berry&email0=sea n_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.
Thanks for the help.

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Sean Berry" <se********@cox.net> wrote in message news:<p%hoc.113536$Jy3.54431@fed1read03>...
the desired result will be in the form

n=2&userid0=sean&username0=Sean%20Berry&email0=sea n_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', 'se********@cox.net'],
['pam', 'Pam Ward', 'p*******@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
Jul 18 '05 #2

P: n/a
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" <kv***********@yahoo.com> wrote in message
news:51**************************@posting.google.c om...
"Sean Berry" <se********@cox.net> wrote in message

news:<p%hoc.113536$Jy3.54431@fed1read03>...
the desired result will be in the form

n=2&userid0=sean&username0=Sean%20Berry&email0=sea n_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', 'se********@cox.net'],
['pam', 'Pam Ward', 'p*******@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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.