= open('test.dat', 'w')
> fo.write('G\xe2teaux')
> fo.close()
>
> fi = open("test.dat",'r')
> fx = codecs.EncodedFile(fi, 'utf-8', 'latin-1')
> astring = fx.readline()
> print astring
> ustring = unicode(ast
x27;G\xe2teaux')
fo.close()
fi = open("test.dat",'r')
fx = codecs.EncodedFile(fi, 'utf-8', 'latin-1')
astring = fx.readline()
print astring
ustring = unicode(astring, 'utf-8' )
print repr(ustring)
print ustring.encode('latin-1')
print us
On 2006-10-19, Leo Kislov <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> It turns out to be troublesome for my case because the
>> EncodedFile object translates calls to readline into calls to
>> read.
>>
>> I believe it ought to raise a NotImplemented exception when
>> readline is called.
>>
Neil Cerutti wrote:
> It turns out to be troublesome for my case because the
> EncodedFile object translates calls to readline into calls to
> read.
>
> I believe it ought to raise a NotImplemented exception when
> readline is called.
>
> As it is it silently causes interactive applications to
>
to 'strict', which causes ValueError to be raised in case an
encoding error occurs.
Base on that, I wrote the following code at startup:
sys.stdout = codecs.EncodedFile(sys.stdout, 'latin-1', 'cp437')
sys.stdin = codecs.EncodedFile(sys.stdin, 'cp437',