d**s 发帖数: 920 | 1 祝大家春节好 !
给大家拜年 !
请教一个Python问题, 怎么读出一个data structure中的全部members(内容) ?
我在用一个的python library, 其中有一个data structure, 我知道它包括很多内容,
我的问题是:
- 怎么知道它包括什么内容 ?
- 怎么把它的内容读出来 ?
我首先想到的是把它转化成一个list,
such as:
a = list(DS) # DS is the data structure
这个会报错说:
TypeError: object is not iterable
请大家帮忙。
======================================================
具体来说: 我想读的是下面一个data structure的内容, 也许你有更具体的建议:
| S*A 发帖数: 7142 | 2 you can try dir(obj) to get a list of the member of the obj.
Depend on how the obj is implemented. dir(obj) might not get
all the member if the obj has its own access function. | d**s 发帖数: 920 | 3 Hi, Thanks,
Yes,members has its own access function.
Is there a simple way to convert such structure to a list ? (Or in C/C++
term, casting to a list ? )
Thanks,
【在 S*A 的大作中提到】 : you can try dir(obj) to get a list of the member of the obj. : Depend on how the obj is implemented. dir(obj) might not get : all the member if the obj has its own access function.
| S*A 发帖数: 7142 | 4 If member has own access function/slots etc,
Unless the class provide an enumerate function for you,
there is no way to enumerate all the members.
In that case, just read the documents. You seems using
some web DOM stuff. The documents should cover what
member is there.
【在 d**s 的大作中提到】 : Hi, Thanks, : Yes,members has its own access function. : Is there a simple way to convert such structure to a list ? (Or in C/C++ : term, casting to a list ? ) : Thanks,
|
|