how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

Ragnar Ouchterlony ragnar at lysator.liu.se
Tue May 29 17:02:36 EDT 2007


tis 2007-05-29 klockan 16:08 -0300 skrev Gabriel Genellina:
> >>>> sys.stdout = filewrapper(sys.stdout, 'utf-8')
> >>>> print u"åäö \N{GREEK CAPITAL LETTER DELTA}"
> >
> > Useful if you don't want to append .encode() to everything you print out
> > that potentially can contain non-ascii letters.
> 
> Isn't the same as codecs.EncodedFile?
> 

No, codecs.EncodedFile() doesn't do exactly the same.

If I understand it correctly, EncodedFile() takes a byte stream as input
and produces another bytestream (with possibly different encoding) as
output in both read and write.

My function (as well as codecs.open()) decodes a byte stream for read
and produces a unicode object or encodes a unicode object for write and
produces a byte stream.

At least, I were unable to create the same behaviour as my filewrapper()
using EncodedFile(). If you are able to do that, I'm interested in how
you do it.

/Ragnar




More information about the Python-list mailing list