[IronPython] IronPython's file object implementation

Dino Viehland dinov at exchange.microsoft.com
Thu Mar 9 17:23:36 CET 2006

The first bug will be fixed in beta 4 - we've done a bunch of cleanup around the file class to make it all around more compatible with CPython.  That not only includes fixing binary mode but also fixing universal new line mode to be much more compatible.  FYI beta 4 should be available real soon now.

The string difference is more complicated.  We do indeed represent all strings as Unicode and that's similar to other implementations of Python such as Jython as well.  But we think that the cases where this incompatibility shines through are pretty rare (unfortunately it sounds like you hit one because you hit another incompatibility, but hopefully fixing the first one will make the 2nd one less of an issue for you).

Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Jonathan Jacobs
Sent: Thursday, March 09, 2006 5:59 AM
To: IronPython List
Subject: [IronPython] IronPython's file object implementation


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
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list