473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Urllib.urlencode question?

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
2 3695
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve Allgood | last post by:
I'm having trouble posting a form at the USPS web site. I've been successful using urllib at other sites, but I'm missing why this won't work: # begin code # get zip+4 import urllib def...
2
by: Andreas Dahl | last post by:
Hi, I use urllib to retrieve data via HTTP. Unfortunately my program crashes after a while (after some loops) because the connection timed out. raise socket.error, msg IOError: (60,...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
1
by: Timothy Wu | last post by:
Hi, I'm trying to fill the form on page http://www.cbs.dtu.dk/services/TMHMM/ using urllib. There are two peculiarities. First of all, I am filling in incorrect key/value pairs in the...
12
by: sleytr | last post by:
Hi, I'm trying to make a gui for a web service. Site using ± character in value of some fields. But I can't encode this character properly. >>> data = {'key':'±'} >>> urllib.urlencode(data)...
1
by: evanpmeth | last post by:
I have tried multiple ways of posting information to a website and have failed. I have seen this problem on other forums can someone explain or point me to information on how POST works through...
0
by: gmguyx | last post by:
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a...
0
by: johnpollard | last post by:
For some reason this script isn't working and I dont know what it is. I believe the problem lies in the following lines of code since the script works with a different website and username/password...
0
by: celery6541 | last post by:
Hi all, I am trying to use urllib.urlencode to post a multidimensional dictionary to a php page. This is the code I am using test = {} test = {} test = "bang"
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.