How can a function find the function that called it?

Mark Wooding mdw at distorted.org.uk
Fri Dec 24 13:58:37 EST 2010


kj <no.email at please.post> writes:

> But OrderedDict's functionality *requires* that its __init__ be
> run, and this __init__, in turn, does part of its initialization
> by calling the update method.
>
> Therefore, the update method of the new subclass needs to be able
> to identify the calling function in order to make a special allowance
> for calls coming from OrderedDict.__init__

That doesn't follow at all.  Why not set a `frozen' flag when your
initialization is complete?  Something like

        class ImmutableOrderedDict (OrderedDict):
          def __init__(me, *args, **kw):
            me._frozen = False
            OrderedDict.__init__(me, *arg, **kw)
            me._frozen = True
          def _check(me):
            if me._frozen:
              raise ImmutableError

And so on.

Thank you for explaining your actual objective, by the way.

-- [mdw]



More information about the Python-list mailing list