Urllib.urlencode question?

S

Sean Berry

I have two lists... one like the following,

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

and the other like this,

list2 ... [['sean', 'Sean Berry', '(e-mail address removed)'], ['pam', 'Pam Ward',
'(e-mail address removed)']]

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=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.


Thanks for the help.
 
K

Konstantin Veretennicov

Sean Berry said:
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', '(e-mail address removed)'],
['pam', 'Pam Ward', '(e-mail address removed)']
]

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
 
S

Sean Berry

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 said:
"Sean Berry" <[email protected]> wrote in message
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', '(e-mail address removed)'],
['pam', 'Pam Ward', '(e-mail address removed)']
]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top