J
Jerry Fleming
Hi,
I have a binary file written with c structures. Each record contains a
null-terminated string followed by two 4-bytes integers. I wrote a small
segment of python code to parse this file in this way:
[coe]
#!/usr/bin/python
from ctypes import *
class Entry(Structure):
_fields_ = ('w', c_char_p), ('s', c_uint, 32), ('l', c_uint, 32)
idx = open('x.idx', 'rb')
str = idx.read(1000)
obj = Entry(str)
print obj.w
print obj.s
print obj.l
[/code]
where the field w is the string, and s and l are the integers. Problem
is that, I can only get the strings, not the integers. Well, I did got
integers, but they are all zeros. What should I do to get the real numbers?
Thanks for help.
- Jerry
I have a binary file written with c structures. Each record contains a
null-terminated string followed by two 4-bytes integers. I wrote a small
segment of python code to parse this file in this way:
[coe]
#!/usr/bin/python
from ctypes import *
class Entry(Structure):
_fields_ = ('w', c_char_p), ('s', c_uint, 32), ('l', c_uint, 32)
idx = open('x.idx', 'rb')
str = idx.read(1000)
obj = Entry(str)
print obj.w
print obj.s
print obj.l
[/code]
where the field w is the string, and s and l are the integers. Problem
is that, I can only get the strings, not the integers. Well, I did got
integers, but they are all zeros. What should I do to get the real numbers?
Thanks for help.
- Jerry