Message75907
With Python 2.x:
>>> 'à' in u'foo'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'in <string>' requires string as left operand
>>> 'à' in u'xàx'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'in <string>' requires string as left operand
The error claims that "'in <string>' requires string as left operand"
when actually the left operand *is* a string.
With Python2.6 with unicode_literals:
>>> print(b'\x85')
à
>>> b'\x85' in 'foo'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand
With Python3.x the error is slightly different:
TypeError: 'in <string>' requires string as left operand, not bytes
but then it works with:
>>> b'f' in 'foo'
True
This problem seems somehow related to the implicit decoding of 'à'. I
guess that 'à' in u'foo' should raise a UnicodeDecodeError ('xxx' codec
can't decode byte 0x85 ...), not a TypeError. |
|
Date |
User |
Action |
Args |
2008-11-15 09:27:24 | ezio.melotti | set | recipients:
+ ezio.melotti |
2008-11-15 09:27:24 | ezio.melotti | set | messageid: <1226741244.61.0.833545368302.issue4328@psf.upfronthosting.co.za> |
2008-11-15 09:27:22 | ezio.melotti | link | issue4328 messages |
2008-11-15 09:27:21 | ezio.melotti | create | |
|