Cプログラムによって作成されたバイナリファイルがいくつかあります。ファイルのPythonのctypesとreadintoを使用して配列を含む構造体を読み取るには?
一つのタイプは、ファイルに次のC構造を記述するためにfwriteのを呼び出すことによって作成された:Pythonで
typedef struct {
unsigned long int foo;
unsigned short int bar;
unsigned short int bow;
} easyStruc;
を次のように、私は、このファイルの構造体をお読みください。
class easyStruc(Structure):
_fields_ = [
("foo", c_ulong),
("bar", c_ushort),
("bow", c_ushort)
]
f = open (filestring, 'rb')
record = censusRecord()
while (f.readinto(record) != 0):
##do stuff
f.close()
こと正常に動作します。私たちの他のタイプのファイルは次の構造を使って作成されます:
typedef struct { // bin file (one file per year)
unsigned long int foo;
float barFloat[4];
float bowFloat[17];
} strucWithArrays;
私はPythonでどのように構造を作成するのか分かりません。
ありがとうございます!どのように私はそれを逃したか分からない。 –