I have these two nested structs in C below
typedef struct tag_interest {
float *high;// array
float *low;// array
} sinterest;
typedef struct tag_sfutures {
int time;
float result;
sinterest *interest;// array
} sfutures;
What is there equivalent in Python?
EDIT I had tried this. I am yet to parse and check this because am still in the process of debugging some code that comes before this.
class CInterest(object):
high = []
low = []
def add_high(self,High):
self.high.append(High)
def add_low(self,Low):
self.low.append(Low)
class CFutures(object):
interest = [CInterest]
def add_interest(self,interest):
self.interest.append(interest)
def set_time(self,time):
self.time = time
def set_put(self,put):
self.put = put
-
@soon please see editsssn– ssn2016年05月01日 15:57:54 +00:00Commented May 1, 2016 at 15:57
1 Answer 1
Take a look at cstruct.
https://pypi.python.org/pypi/cstruct
It will take your struct definition as a string and create a Python class you can use, instantiate and pack/unpack binary data. I use it to auto generate hundreds of C structures with no issues other than its list of C primitives is not comprehensive.
Sign up to request clarification or add additional context in comments.
lang-py