Python/C#, Reading File into Byte Array - Not Quite the Same Result -


i'm attempting read file , process in both c# , ironpython, i'm running slight problem.

when read file in either language, byte array that's almost identical, not quite.

for instance, array has 1552 bytes. they're same except 1 thing. time value "10" appears in python implementation, value "13" appears in c# implementation. aside that, other bytes same.

here's i'm doing bytes:

python:

f = open('c:\myfile.blah') contents = f.read() bytes = bytearray(contents, 'cp1252') 

c#:

var bytes = file.readallbytes(@"c:\myfile.blah"); 

perhaps i'm choosing wrong encoding? though wouldn't think so, since python implementation behaves expect , processes file successfully.

any idea what's going on here?

(i don't know python) looks need pass 'rb' flag:

open('c:\myfile.blah', 'rb') 

reference:

on windows, 'b' appended mode opens file in binary mode, there modes 'rb', 'wb', , 'r+b'. python on windows makes distinction between text , binary files; end-of-line characters in text files automatically altered when data read or written.

  • note values 10 , 13 give clues problem is: line feed 10 in decimal , carriage return 13 in decimal.

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -