Thanks Walter, I think I've got the lay of the land roughly, but my grasp is still light and imperfect. I'm pretty confident I shouldn't be doing anything like what you're describing for the level of coding I'm doing, but it's interesting to see the approach.
Keith On Fri, Jan 3, 2014 at 6:56 PM, Walter Prins <wpr...@gmail.com> wrote: > Hi, > > The code in my last post got line wrapped which will break if directly > tried out. To avoid possible confusion I paste a version below with > shorter lines which should avoid the problem: > > > import gc, itertools > > def names_of(obj): > """Try to find the names associated to a given object.""" > #Find dict objects from the garbage collector: > refs_dicts = (ref for ref in gc.get_referrers(obj) > if isinstance(ref, dict)) > #Get a single chained generator for all the iteritems() iterators > #in all the dicts > keyvalue_pairs = itertools.chain.from_iterable( > refd.iteritems() for refd in refs_dicts) > #Return a list of keys (names) where the value (obj) is the one > #we're looking for: > return [k for k, v in keyvalue_pairs if v is obj] > > x = [] > y = x > z = [x] > > print names_of(z[0]) > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Keith
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor