[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

Hi,

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))

CPython:
01044c1045a1470ec2011201000020000000ec0f0000030000006f1e0000fcc5

IronPython:
01044c1045470e0112010000200000000f0000030000006f1e000052441d3641

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.
--
Jonathan

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
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list