Get reference to "owner"
Gerhard Häring
gh_pythonlist at gmx.de
Tue Mar 5 02:26:55 EST 2002
Le 05/03/02 à 01:41, Robert Oschler écrivit:
> I've never seen this feature in any programming language I've worked in but
> it can't hurt to ask. Can an aggregated class object get a reference to the
> class object that aggregates it? So if ClassAggregator contained an
> instance of ClassAggregatee is there a Python syntax/construct that a
> function in ClassAggregatee could use to get a reference to the instance of
> ClassAggregator that contained it?
I've no idea what you're talking about. But this doesn't hinder me from
replying ;-) You want to do something like the following?
import sys, traceback
class A:
def __init__(self):
self.b = B()
class B:
def __init__(self):
# Determine here from where we're instantiated
a = A()
If this is possible at all, I think it will involve the traceback
module. I can't currently think of a complete solution, though. With
traceback.extract_stack, one could easily determine the line you're
called from, but I can't think of a way to determine the class.
Gerhard
--
This sig powered by Python!
Außentemperatur in München: 1.9 °C Wind: 0.8 m/s
More information about the Python-list
mailing list