[IronPython] IronPython's file object implementation

Jonathan Jacobs korpse-ironpython at kaydash.za.net
Thu Mar 9 14:59:07 CET 2006


I've got a gripe with IronPython's file implementation. The following code 
produces two different results in CPython and IronPython:

print ''.join('%02x' % ord(c) for c in file('some_binary_file').read(32))



One of the causes of this appears to be the fact that PythonFile is 
implemented using a StreamReader, for binary mode, which attempts to decode 
data that is read from the underlying stream, which is not how Python's file 
object works.
Another problem (that contributes to the confusion) is that IronPython 
represents Python's "str" type as .NET's "string" type which is described as 
something that "Represents text as a series of Unicode characters", whereas 
"str" is actually more like a byte[], while "unicode" is more like .NET's 
"string" type.

When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
                 -- Rinzai, ninth century Zen master

More information about the Ironpython-users mailing list