Intercepting binding?

Xavier Ho contact at
Thu Sep 24 03:10:53 CEST 2009

Here's a **very** hackish code I threw up together. It requires a lot of
manual checking and, I don't think it's practical at all.


default = set(locals())

class test():
    def __init__(self): = str(self)
        self.val = 'Mrra'

a = test()
user = set(locals()) - default
loc = dict(locals())

for item in loc.items():
    if item[0] in user:

('a', <__main__.test object at 0x0000000002D6A240>)
('default', {'__builtins__', '__name__', '__file__', '__doc__',
('test', <class '__main__.test'>)


Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at

On Thu, Sep 24, 2009 at 10:49 AM, Rhodri James
<rhodri at>wrote:

> On Thu, 24 Sep 2009 01:34:35 +0100, andrew cooke <andrew at>
> wrote:
>> For example, I assume it's possible to somehow access the dictionary
>> for the current block, but I can't see how to do this after
>> assignment.  If I do it in the Foo constructor, for example, "a" will
>> not yet be bound.
> I apologise for failing to notice earlier that you know what you're
> talking about.  I blame the hour :-)
> I'm not sure you can access the namespace dictionary of the "current
> block" (module?), that's the problem.  Oh, except via locals(), which
> might do exactly what you're after depending.  Excuse me, I'm being
> very dim tonight.
> --
> Rhodri James *-* Wildebeest Herder to the Masses
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list