trouble w/ unicode file

Serge Orlov sombDELETE at pobox.ru
Sun Jan 25 11:39:11 EST 2004


"Guilherme Salgado" <salgado at freeshell.org> wrote in message news:mailman.766.1075043602.12720.python-list at python.org...
> On Sun, 2004-01-25 at 06:54, Serge Orlov wrote:
> > "Guilherme Salgado" <salgado at freeshell.org> wrote in message news:mailman.752.1074995324.12720.python-list at python.org...
> > > Hi there,
> > >
> > > I have a python source file encoded in unicode(utf-8) with some
> > > iso8859-1 strings. I've encoded this file as utf-8 in the hope that
> > > python will understand these strings as unicode (<type 'unicode'>)
> > > strings whithout the need to use unicode() or u"" on these strings. But
> > > this didn't happen.
> >
> > You hoped, but you forgot to pray <wink> Why do you think Python
> > should behave this way? There is (an experimental?) option -U that
>
> Ok, ok. I'll remember to pray next time. :-)
> I need to store unicode strings(declared in files) in ZODB, but i don't
> want to use u"" around all my strings (cause most of them are latin-1),
> so i think storing the file as unicode will work. Is there a better way
> for doing this?

Not that I'm aware of.

> > We have a bug here as well. But in your code. The coding must
> > be the same as the coding of your source file. bar.py must be:
> > #-*- coding: latin-1 -*-
> > x = 'ééééáááááííí'
> > print x, type(x)
> >
>
> I didn't understand this (even after some pray) :-)
> My file is encoded in utf-8, look:
> $ file bar.py
> bar.py: UTF-8 Unicode text
>
> Why should i declare it as latin1 encoded though?

Sorry, I was confused by your words "with some iso8859-1 strings".
I thought you were using simple (unaware of encodings) editor and
just added #-*- coding: utf-8 -*- with hope that it will work. You're
right the coding should stay utf-8. After that you have two options:
either use -U option or put u before every string.

-- Serge.







More information about the Python-list mailing list