tags:

views:

42

answers:

2

Hi there,

I'm trying to find information on different ways to traverse an object tree in python. I don't know much about the language in general yet, so any suggestions/techniques would be welcome.

Thanks so much jml

+1  A: 

See the inspect module. It has functions for accessing/listing all kinds of object information.

Lukáš Lalinský
This is inapplicable. OP is really trying to extract data from a deserialized JSON file, not figure out things about strange objects at runtime.
Mike Graham
ok; i also found out about the help(someobject) functionality. very handy
jml
mike; you are right. i found out more from just printing type(someobject["membername"])
jml
Well, who could have known that. The question makes it look like the problem is traversing of unknown objects.
Lukáš Lalinský
A: 

i found out how to do it. basically myobject.membername1.membername2

jml
i think the type(myobj.someparam) trick was the most useful to me, as it helps one find out how to address a given portion of an object. this was the most confusing point for me originally; that a single list object (for ex) could contain a number of differing data types.
jml