Re: Using codecs.EncodedFile() with Python 2.5

2007-01-03 Thread Peter Otten
= 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

Using codecs.EncodedFile() with Python 2.5

2007-01-03 Thread David Hughes
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

Re: codecs.EncodedFile

2006-10-18 Thread Neil Cerutti
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. >>

Re: codecs.EncodedFile

2006-10-18 Thread Leo Kislov
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 >

codecs.EncodedFile

2006-10-18 Thread Neil Cerutti
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',