[Tutor] Converting from unicode to nonstring

David Hutto smokefloat at gmail.com
Fri Oct 15 13:53:37 CEST 2010

On Thu, Oct 14, 2010 at 6:56 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "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 doing
> things in a way you wouldn't if it was normal raw_input you were using.

Not spook, but I couldn't think of another way of placing it into a
variable for a function within the script, without it using the
literal value from the db, (without generating a blank.py file, and
rewriting the whole class each time for the changes in the value), and
use it in the code without it being a literally evaluated u'string'
the way it came from the db

> HTH,
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list