codecs UTF_streamreader()

David Phoon david.phoon at retriever.com.au
Thu Jan 24 23:03:34 EST 2002


i would like to know if there is pass a filehandle that is not returned
by the open below in streamwriter and streamreader by opening a file
stored to disk. eg for the example
taken from the python 2.2


can you convert a string to a file like object and somehow pass it to
the
UTF8_streamreader(file)

I tried to do something  like
data = StringIO.StringIO
data was then populated with a UTF-8 string
and populating it and passing it to UTF8_streamreader(data,) but without
success

data

##################################
import codecs

unistr = u'\u597d ...'

unistr = u'\u0660\u2000ab ...'
(UTF8_encode, UTF8_decode, UTF8_streamreader, UTF8_streamwriter) =
codecs.lookup('UTF-8')

output = UTF8_streamwriter( open(
'/home/david/davidwk/python/testmime/a.txt', 'wb') )
output.write( unistr )
output.close()

input = UTF8_streamreader( open(
'/home/david/davidwk/python/testmime/a1.txt', 'rb') )
print repr(input.read())
input.close()

##########################





More information about the Python-list mailing list