Re: Easily convert unicode tuple to python string tuple???

Discussion in 'Python' started by Bill Scherer, Apr 20, 2004.

  1. Bill Scherer

    Bill Scherer Guest

    Michal Mikolajczyk wrote:

    > Is there a quick way to convert a unicode tuple to a tuple containing
    > python strings?
    >
    > (u'USER', u'NODE', u'HASH', u'IDNBR')
    >
    > to this:
    >
    > ('USER', 'NODE', 'HASH', 'IDNBR')


    >>> a = (u'USER', u'NODE', u'HASH', u'IDNBR')
    >>> tuple([e.encode() for e in a])

    ('USER', 'NODE', 'HASH', 'IDNBR')

    > I need to be able to do this for a lot of tuples, not just one.



    for aTuple in myTuples:
    newTuple = tuple([e.encode() for e in aTuple])
    ...


    You may need to alter your encoding, depending on your environment.

    > Thanks,
    > Michael



    HTH,

    Bill
     
    Bill Scherer, Apr 20, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    1
    Views:
    812
    Larry Bates
    Apr 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    961
    Jeff Epler
    Apr 20, 2004
  3. Chris  Song
    Replies:
    3
    Views:
    272
    Ganesan Rajagopal
    Dec 27, 2005
  4. Jeremy
    Replies:
    1
    Views:
    810
    Alex Willmer
    Jan 11, 2011
  5. Jeremy
    Replies:
    0
    Views:
    580
    Jeremy
    Jan 11, 2011
Loading...

Share This Page