[Tutor] Converting from unicode to nonstring
David Hutto
smokefloat at gmail.com
Thu Oct 14 17:16:27 CEST 2010
On Thu, Oct 14, 2010 at 10:14 AM, David Hutto <smokefloat at gmail.com> wrote:
> Hey Buddy Pals,
>
> I receive the following output from a sqlite db
>
> (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])
>
> And I use the following to replace [1,2,3,4] with
> self.plot from line 13 in belows iteration:
>
> self.orderbygname = self.cur.execute('''select * from %s order by
> graphname''' % ('graphs'))
> self.orderlist = []
> for name in self.orderbygname:
> self.orderlist.append(name)
> self.fig = Figure()
> for line in self.orderlist:
> print line
> #print line[0],' and ', line[1]
> self.graphname = line[0]
> self.graphtype = line[1]
> self.position = line[2]
> self.bgcolor = line[3]
> self.plot = line[4]
> self.grid = line[5]
> self.x_y_axis_range = line[6]
>
> I get the error:
>
> ValueError: invalid literal for float(): 1,2,3,4# Which is a deceptive error, because it means
that the u'value here' has not been converted to value, not the string
'value', but the actual.
It works if I place the same value in manually, converting it is the
actual problem.
>
> So my question is, how do I convert the unicode '' to a plain nonstring insert?
Or somehow append to the u'string' an escape character \ for the ''?
>
> Thanks,
> David
>
More information about the Tutor
mailing list