Urllib.urlencode question?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Berry

    Urllib.urlencode question?

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

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

    and the other like this,

    list2 ... [['sean', 'Sean Berry', 'sean_berry@cox .net'], ['pam', 'Pam Ward',
    'pam_ward@cox.n et']]

    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.urlencod e and zipping the two lists together. But
    the desired result will be in the form

    n=2&userid0=sea n&username0=Sea n%20Berry&email 0=sean_berry%40 cox.net&userid1 =
    pam&username1=P am%20Ward&email 1=pam_ward%40co x.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.



  • Konstantin Veretennicov

    #2
    Re: Urllib.urlencod e question?

    "Sean Berry" <sean_berry@cox .net> wrote in message news:<p%hoc.113 536$Jy3.54431@f ed1read03>...[color=blue]
    > the desired result will be in the form
    >
    > n=2&userid0=sea n&username0=Sea n%20Berry&email 0=sean_berry%40 cox.net&userid1 =
    > pam&username1=P am%20Ward&email 1=pam_ward%40co x.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.
    >[/color]

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

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

    pairs = [('n', len(users))]
    for i, u in enumerate(users ):
    numbered_fields = [f + str(i) for f in fields]
    pairs += zip(numbered_fi elds, u)

    import urllib
    print urllib.urlencod e(pairs)


    - kv

    Comment

    • Sean Berry

      #3
      Re: Urllib.urlencod e question?

      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@ yahoo.com> wrote in message
      news:5155aad2.0 405120732.646a9 8d4@posting.goo gle.com...[color=blue]
      > "Sean Berry" <sean_berry@cox .net> wrote in message[/color]
      news:<p%hoc.113 536$Jy3.54431@f ed1read03>...[color=blue][color=green]
      > > the desired result will be in the form
      > >
      > >[/color][/color]
      n=2&userid0=sea n&username0=Sea n%20Berry&email 0=sean_berry%40 cox.net&userid1 =[color=blue][color=green]
      > > pam&username1=P am%20Ward&email 1=pam_ward%40co x.net
      > >
      > > How can achieve adding the numbers to the end of the variable names so[/color][/color]
      that[color=blue][color=green]
      > > they can be used by Flash's loadVars function.
      > >[/color]
      >
      > I don't know anything about Flash loadVars, but how about this:
      >
      > fields = ['userid', 'username', 'email']
      > users = [
      > ['sean', 'Sean Berry', 'sean_berry@cox .net'],
      > ['pam', 'Pam Ward', 'pam_ward@cox.n et']
      > ]
      >
      > pairs = [('n', len(users))]
      > for i, u in enumerate(users ):
      > numbered_fields = [f + str(i) for f in fields]
      > pairs += zip(numbered_fi elds, u)
      >
      > import urllib
      > print urllib.urlencod e(pairs)
      >
      >
      > - kv[/color]


      Comment

      Working...