comparing Unicode and string

Leo Kislov Leo.Kislov at gmail.com
Fri Nov 10 18:18:52 EST 2006


Neil Cerutti wrote:
> On 2006-11-10, Steve Holden <steve at holdenweb.com> wrote:
> >>> But I don't insist on my PEP. The example just shows just
> >>> another pitfall with Unicode and why I'll advise to any
> >>> beginner: Never write text constants that contain non-ascii
> >>> chars as simple strings, always make them Unicode strings by
> >>> prepending the "u".
> >>
> >> That doesn't do any good if you aren't writing them in unicode
> >> code points, though.
> >
> > You tell the interpreter what encoding your source code is in.
> > It then knows precisely how to decode your string literals into
> > Unicode. How do you write things in "Unicode code points"?
>
> for = u"f\xfcr"

Unless you're using unicode unfriendly editor or console, u"f\xfcr" is
the same as u"für":

>>> u"f\xfcr" is u"für"
True

So there is no need to write unicode strings in hexadecimal
representation of code points.

  -- Leo




More information about the Python-list mailing list