unicode

7stud bbxx789_05ss at yahoo.com
Mon Jul 2 06:00:31 CEST 2007


On Jul 1, 9:51 pm, 7stud <bbxx789_0... at yahoo.com> wrote:
> Hi,
>
> Thanks for the detailed response.
>
> On Jul 1, 2:14 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
>
> > > 1) If you print a unicode string:
>
> > > a) str() calls encode(), and encode() tries to convert the unicode
> > > string to a regular string.  encode() uses the default encoding, which
> > > is ascii.  If encode() can't convert a character, then encode() raises
> > > an exception.
>
> > Yes and no. This is what str() does, but str() isn't called. Instead,
> > print inspects sys.stdout.encoding, and uses that encoding to encode
> > the string. That, in turn, may raise an exception (in particular if
> > sys.stdout.encoding is "ascii" or not set).
>
> Is that the same as print calling encode(u_str, sys.stdout.encoding)

ooops.  I mean is that the same as print calling
u_str.encode(sys.stdout.encoding)?




More information about the Python-list mailing list