0

How to Convert This C# Code Into Python Code?

Stream stream = new FileStream("items.dat", FileMode.Open); byte[] useForIntReading = new byte[4]; byte[] useForShortReading = new byte[4]; int itemCount = 0; short unused = 0; stream.Read(useForShortReading, 0, 2); unused = BitConverter.ToInt16(useForShortReading, 0); stream.Read(useForIntReading, 0, 4); temCount = BitConverter.ToInt32(useForIntReading, 0);

30th Nov 2020, 10:36 AM
Haikal Dz
Haikal Dz - avatar
1 Odpowiedź
0
I don't know C# but I think this should work in Python3 # We open the file in binary mode. file = open("items.dat", "rb") # We read two bytes useForShortReading = file.read(2) # To convert it to an integer. # You should store this anywhere. int.from_bytes(useForShortReading, byteorder, signed) # The byteorder is either "little" or "big" and signed is a Boolean. # You can also write it in one line. # I'm writing the next part in one line. int.from_bytes(file.read(4))
9th Dec 2020, 7:16 AM
Jjjjjjjj
Jjjjjjjj - avatar