Walking an object/reference graph

Discussion in 'Python' started by Austin Bingham, Oct 5, 2009.

  1. I'm looking for the proper way to "walk" a graph of python objects. My
    specific task is to find all objects of a given type that are referred
    to (transitively) by some starting object. My approach has been to
    loop through the object's attributes, examining each, and then
    recursing on them.

    This approach has immediate problems in that I immediately hit
    infinite recursion due to method-wrappers; I'm not sure *exactly*
    what's going on, but it appears that method-wrappers refer to
    method-wrappers ad infinitum. If I add code to avoid this issue,
    others soon crop up, so before I wrote too much more code, I thought
    I'd check with experts to see if there's a better way.

    So, if I've explained what I'm looking for well enough, does anyone
    know of a proper way to walk a graph of object references? I need to
    support cycles in the graph, so keeping track of visited object IDs or
    something will have to be employed. Also, I need to be able to follow
    references stored in lists, dictionaries, etc...basically any way to
    programatically get from one object to another should be followed by
    the algorithm. I feel like I'm missing something simple, but perhaps
    this is just a tricky problem for python. Any ideas or insight would
    be great. Thanks!

    Austin
     
    Austin Bingham, Oct 5, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Sakkis
    Replies:
    1
    Views:
    477
    Szabolcs Nagy
    Jan 29, 2007
  2. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    673
    Dr Ann Huxtable
    Dec 21, 2004
  3. Jef Driesen
    Replies:
    3
    Views:
    2,621
    mlimber
    Jan 24, 2006
  4. Almoni
    Replies:
    0
    Views:
    3,143
    Almoni
    Jan 17, 2010
  5. Emilio Mayorga
    Replies:
    6
    Views:
    380
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page