[Tutor] Converting from unicode to nonstring

David Hutto smokefloat at gmail.com
Thu Oct 14 21:21:45 CEST 2010


On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark <adam.jtm30 at gmail.com> wrote:
> On 14/10/10 19:29, David Hutto wrote:
>>
>> On Thu, Oct 14, 2010 at 2:19 PM, Sander Sweers<sander.sweers at gmail.com>
>>  wrote:
>>
>>>
>>> On 14 October 2010 16:14, David Hutto<smokefloat at gmail.com>  wrote:
>>>
>>>>
>>>> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>>>>
>>>> Which is a tuple of unicode strings. From this I
>>>> need to place portions of the tuple into other fields,
>>>> but not as unicode strings, but literals no ''.
>>>>
>>>> For example if I have the following line:
>>>>
>>>> self.lines = self.newplot.plot([1,2,3,4])
>>>>
>>>
>>> So you want convert string u'1,2,3,4' to a list of ints [1,2,3,4]?
>>> Then the below will work.
>>>
>>> [int(n) for n in u'1,2,3,4'.replace(',', '')]
>>>
>>>
>>
>> Actually, I needed it to be converted to something without a string
>> attached to it. See a post above, and it was fixed by eval(),
>>
>> Thanks though. And I'm sure at some point this morning in a moment of
>> frustration rather than logic, I tried your approach.
>>
>
> What do you mean by "without a string attached to it"?
> Also using eval could be dangerous unless you're sure the stuff coming out
> of your dbase is safe.
>
Read the above posts and it should be explanation enough.


More information about the Tutor mailing list