John Machin wrote:
> When mixing unicode strings with byte strings, Python attempts to
> decode the str object to unicode, not encode the unicode object to
> str.
Thanks for the explanation. Of course I didn't want to mix Unicode and Latin
in one string, my snippet just tried to illustrate the p
On Jan 10, 1:55 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-01-09 at 15:33 +0100, Fredrik Lundh wrote:
> > When mixing Unicode with byte strings, Python attempts to decode the
> > byte string, not encode the Unicode string.
>
> Ah, I did not realize that. I never mix Unicode and byt
On Wed, 2008-01-09 at 15:33 +0100, Fredrik Lundh wrote:
> When mixing Unicode with byte strings, Python attempts to decode the
> byte string, not encode the Unicode string.
Ah, I did not realize that. I never mix Unicode and byte strings in the
first place, and now I know why. Thanks for clearing
Carsten Haese wrote:
> If that really is the line that barfs, wouldn't it make more sense to
> repr() the unicode object in the second position?
>
> import sys
> for k in sys.stdin:
> print '%s -> %s' % (k, repr(k.decode('iso-8859-1')))
>
> Also, I'm not sure if the OP has told us the truth
On Wed, 2008-01-09 at 13:44 +0100, Fredrik Lundh wrote:
> Robert Latest wrote:
>
> > Here's a test snippet...
> >
> > import sys
> > for k in sys.stdin:
> > print '%s -> %s' % (k, k.decode('iso-8859-1'))
> >
> > ...but it barfs when actually fed with iso8859-1 characters. How is this
> > do
Robert Latest wrote:
> Here's a test snippet...
>
> import sys
> for k in sys.stdin:
> print '%s -> %s' % (k, k.decode('iso-8859-1'))
>
> ...but it barfs when actually fed with iso8859-1 characters. How is this
> done right?
it's '%s -> %s' % (byte string, unicode string) that barfs. try
Robert Latest wrote:
> ...but it barfs when actually fed with iso8859-1 characters.
Specifically, it says:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 0:
ordinal not in range(128)
which doesn't make sense to me, because I specifically asked for the
iso8859-1 decoder, n
Here's a test snippet...
import sys
for k in sys.stdin:
print '%s -> %s' % (k, k.decode('iso-8859-1'))
...but it barfs when actually fed with iso8859-1 characters. How is this
done right?
robert
--
http://mail.python.org/mailman/listinfo/python-list