我如何在python中创建结构的结构?

时间:2012-06-22 13:58:22

标签: python-3.x

我希望在python中实现以下C结构,并希望能够访问如下所述的成员。任何帮助表示赞赏

typedef struct{
    unsigned int ch_state;
    unsigned int polling;
    unsigned int timeout;
    unsigned int count;
}channel_Status_t;

typedef struct{
 channel_Status_t  ch_status;
}channel_num_t

typedef struct{   
    channel_num_t SR1;
    channel_num_t SR2;
    channel_num_t LR1;
    channel_num_t LR2;
} channel_type_t;

channel_type_t Rx;
channel_type_t Tx;

Rx.SR1.ch_status.ch_state=1;
Rx.SR1.ch_status.polling=10;
Rx.SR1.ch_status.polling=20;
Rx.SR1.ch_status.count=0;

// Should be able to access data as below... 
Rx.SR2.ch_status.ch_state=1;
Rx.SR2.ch_status.polling=10;
Rx.SR2.ch_status.polling=20;
Rx.SR2.ch_status.count=0;

1 个答案:

答案 0 :(得分:1)

你很可能想要从每个结构中创建一个类。