Easily convert unicode tuple to python string tuple???

Bill Scherer Bill.Scherer at VerizonWireless.com
Tue Apr 20 11:34:30 EDT 2004


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





More information about the Python-list mailing list