Re: comparing Unicode and string

2006-11-10 Thread Leo Kislov
Neil Cerutti wrote: > On 2006-11-10, Steve Holden <[EMAIL PROTECTED]> 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,

Re: comparing Unicode and string

2006-11-10 Thread Neil Cerutti
On 2006-11-10, Steve Holden <[EMAIL PROTECTED]> 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 stri

Re: comparing Unicode and string

2006-11-10 Thread Steve Holden
Neil Cerutti wrote: > On 2006-11-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> Marc 'BlackJack' Rintsch wrote: >>> Why? Python strings are *byte strings* and bytes have values in the range >>> 0..255. Why would you restrict them to ASCII only? >> Because getting an exception when comparing

Re: comparing Unicode and string

2006-11-10 Thread Neil Cerutti
On 2006-11-10, John Machin <[EMAIL PROTECTED]> wrote: > > Neil Cerutti wrote: >> On 2006-10-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> > Hello, >> > >> > here is something that surprises me. >> > >> > #coding: iso-8859-1 >> >> I think that's supposed to be: >> >> # -*- coding: iso-8859-1

Re: comparing Unicode and string

2006-11-10 Thread Neil Cerutti
On 2006-11-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch wrote: >> Why? Python strings are *byte strings* and bytes have values in the range >> 0..255. Why would you restrict them to ASCII only? > > Because getting an exception when comparing a string with a unicode

Re: comparing Unicode and string

2006-11-09 Thread John Machin
Neil Cerutti wrote: > On 2006-10-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello, > > > > here is something that surprises me. > > > > #coding: iso-8859-1 > > I think that's supposed to be: > > # -*- coding: iso-8859-1 -*- > Not quite. As PEP 263 says: """ More precisely, the first

Re: comparing Unicode and string

2006-11-09 Thread [EMAIL PROTECTED]
Marc 'BlackJack' Rintsch wrote: > Why? Python strings are *byte strings* and bytes have values in the range > 0..255. Why would you restrict them to ASCII only? Because getting an exception when comparing a string with a unicode string is irritating. But I don't insist on my PEP. The example ju

Re: comparing Unicode and string

2006-10-23 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > I didn't mean that the *assignment* should raise exception. I mean that > any string constant that cannot be decoded using > sys.getdefaultencoding() should be considered a kind of syntax error. Why? Python strings are *byte strings* and bytes h

Re: comparing Unicode and string

2006-10-23 Thread [EMAIL PROTECTED]
I didn't mean that the *assignment* should raise exception. I mean that any string constant that cannot be decoded using sys.getdefaultencoding() should be considered a kind of syntax error. I agree of course with the argument of backward compatibility, which means that my suggestion is for Python

Re: comparing Unicode and string

2006-10-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Suggestion: shouldn't an error raise already when I try to assign s2? variables are not typed in Python. plain assignment will never raise an exception. -- http://mail.python.org/mailman/listinfo/python-list

Re: comparing Unicode and string

2006-10-20 Thread Leo Kislov
[EMAIL PROTECTED] wrote: > Thanks, John and Neil, for your explanations. > > Still I find it rather difficult to explain to a Python beginner why > this error occurs. > > Suggestion: shouldn't an error raise already when I try to assign s2? A > normal string should never be allowed to contain char

Re: comparing Unicode and string

2006-10-19 Thread Neil Cerutti
On 2006-10-19, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Suggestion: shouldn't an error raise already when I try to > assign s2? There's been discussion on pydev about changing this, but for now I believe a str is a sequence of bytes in Python, rather than a string of characters. My current p

Re: comparing Unicode and string

2006-10-19 Thread [EMAIL PROTECTED]
Thanks, John and Neil, for your explanations. Still I find it rather difficult to explain to a Python beginner why this error occurs. Suggestion: shouldn't an error raise already when I try to assign s2? A normal string should never be allowed to contain characters that are not codable using the

Re: comparing Unicode and string

2006-10-16 Thread Neil Cerutti
On 2006-10-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > here is something that surprises me. > > #coding: iso-8859-1 I think that's supposed to be: # -*- coding: iso-8859-1 -*- The special comment changes only the encoding of unicode literals. In particular, it doesn't change

Re: comparing Unicode and string

2006-10-16 Thread John Roth
[EMAIL PROTECTED] wrote: > Hello, > > here is something that surprises me. > > #coding: iso-8859-1 > s1=u"Frau Müller machte große Augen" > s2="Frau Müller machte große Augen" > if s1 == s2: > pass > > Running this code produces a UnicodeDecodeError: > > Traceback (most recent call l