Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Easily convert unicode tuple to python string tuple??? (http://www.velocityreviews.com/forums/t330058-re-easily-convert-unicode-tuple-to-python-string-tuple.html)

Bill Scherer 04-20-2004 03:34 PM

Re: Easily convert unicode tuple to python string tuple???
 
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




All times are GMT. The time now is 05:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.