0

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
asked May 1, 2016 at 4:50
1
  • @soon please see edits Commented May 1, 2016 at 15:57

1 Answer 1

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.

answered May 1, 2016 at 5:07
Sign up to request clarification or add additional context in comments.

3 Comments

sharing link is not a good answer, please share more detail of your solution
Figuring this out should be simple enough. I provide help and hints, but I will not solve the problem.
so better put it as a comment not answer

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.