2016-05-01 52 views
0

我有這兩個嵌套的結構在下面C你如何重建這些結構在Python

typedef struct tag_interest { 
    float *high;// array 
    float *low;// array 
} sinterest; 

typedef struct tag_sfutures { 
    int time; 
    float result; 
    sinterest *interest;// array 
} sfutures; 

有什麼相當於在Python?

編輯 我試過了。我還沒有解析和檢查,因爲我仍然在調試之前的一些代碼。

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 
+0

@soon請參閱編輯 – ssn

回答

1

看看cstruct。

https://pypi.python.org/pypi/cstruct

這將需要你的結構定義爲一個字符串,並創建可以使用,實例化和包裝/解包二進制數據Python類。我使用它來自動生成數百個C結構,除了C原語列表不全面外,沒有任何問題。

+0

分享鏈接不是一個好的答案,請分享您的解決方案的更多細節 – Mostafiz

+0

找出這個應該足夠簡單。我提供幫助和提示,但我不會解決問題。 – Richard

+3

所以最好把它作爲一個評論,而不是回答 – Mostafiz