[Tutor] Confusing Unicode Conversion Problem.

Chris Hengge pyro9219 at gmail.com
Wed Dec 13 22:06:26 CET 2006


You fixed it! Kudos and a cookie! (Name Brand even!)

Thanks a lot, seems to be moving along fine now.. :]

On 12/13/06, Tim Golden <mail at timgolden.me.uk> wrote:
>
> [Chris H]
> > The reason I an forcing each line to string and splitting it is because
> the
> > pure numeric values coming from the excel sheet all come in a decimal,
> and
> > have an appended .0 at the end.
>
> Ah! You're using str to convert a number to a string. I see.
> And you're relying on the fact that other data, such as
> the mysterious "FRAMERISER\xa0" won't be affected by a split
> on a dot.
>
> Try using the unicode function as a converter, rather
> than str. If the input is already a unicode object, it
> won't alter it; if it's a number, it'll convert to a
> unicode string, and the split will work as expected.
>
> <code snippet>
> while xlSht.Cells(row,col).Value != None:
>      tempValue = xlSht.Cells(row,col).Value
>      tempString = unicode (tempValue).split('.')[0]
>      # tempString is now a unicode object one way
>      # or the other, representing the part of your
>      # data before the dot.
> </code snippet>
>
> You might want to convert numbers back to some kind
> of numeric type here (Decimal or float or int)
> depending on your requirements later.
>
> > The destination for the list (you guessed correct) is another loop that
> > creates SQL commands, and then posts them into a database.
>
> Depending on what your database is expecting, you might need to
> encode your Unicode, or not. If you're using sqlite, for example,
> it's expecting Unicode in any case. Other databases and interface
> modules may vary.
>
> Hope that's a bit clearer. I'm always happy to explain
> again, but if my explanation isn't clear this time
> round, better if someone else has a go; maybe my style
> of explanation doesn't match with your style of
> understanding. :)
>
> TJG
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061213/aff76b33/attachment.htm 


More information about the Tutor mailing list