[Tutor] Converting from unicode to nonstring
alan.gauld at btinternet.com
Fri Oct 15 00:56:11 CEST 2010
"David Hutto" <smokefloat at gmail.com> wrote
> In other words I needed (1,2,3,4) not u'(1,2,3,4)' to be inserted
> for variable self.plot
You appear to be making this much more difficult than it needs to be.
The values you retrieve from the database are strings (forget about
the unicode aspect its not really relevant here) just as if you had
used raw_input to read them from the user.
How would you convert a string received from raw_input() to a series
of numbers? Would you have used eval() or just split the string and
called int() or float()? Something like:
inp = raw_input("Enter a string of numbers separated by commas")
nums = [int(n) for n in inp.split(',')]
eval() should always be considered a last resort because of the
potential for causing damage and the extremely obscure errors
it can throw up with badly formed input.
I think you are letting the unicode representation spook you into
things in a way you wouldn't if it was normal raw_input you were
Author of the Learn to Program web site
More information about the Tutor