[IronPython] Reading Text files with open

Fuzzyman fuzzyman at voidspace.org.uk
Tue Jun 12 01:13:39 PDT 2007


John Messerly wrote:

>Actually, it's a result of System.Text.ASCIIEncoding, which replaces bytes greater than 0x7f with a question mark. I filed this as CodePlex work item #10983 (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=10983).
>
>  
>
Thanks. With CPython, the only difference between reading with 'r' and 
'rb' is the handling of newlines.

Michael
http://www.voidspace.org.uk/ironpython/index.shtml


>Thanks,
>
>John
>
>-----Original Message-----
>From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
>Sent: Monday, June 11, 2007 4:04 PM
>To: Discussion of IronPython
>Subject: [IronPython] Reading Text files with open
>
>Hello all,
>
>If I create a file with the following code:
>
>open(r'c:\temp\test.txt', 'w').write('\xa33')
>
>And then read it in using the Python 'open', I get different results
>with Python and IronPython:
>
>CPython 2.4.4:
>
> >>> data = open(r'c:\temp\test.txt').read()
> >>> data
>'\xa33'
> >>> ord(data[0])
>163
>
>IronPython 1.1:
>
> >>> data = open(r'c:\temp\test.txt').read()
> >>> data
>'?3'
> >>> ord(data[0])
>63
>
>If I use the 'rb' flag with IronPython then the right thing happens, but
>this isn't binary data...
>
>Is there any way round this - I guess it is a consequence of .NET strings.
>
>Michael
>_______________________________________________
>users mailing list
>users at lists.ironpython.com
>http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>  
>



More information about the users mailing list