Intercepting binding?

Xavier Ho contact at xavierho.com
Wed Sep 23 21:10:53 EDT 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.

###input:

default = set(locals())

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

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

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

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

Cheers,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
Website: http://xavierho.com/


On Thu, Sep 24, 2009 at 10:49 AM, Rhodri James
<rhodri at wildebst.demon.co.uk>wrote:

> On Thu, 24 Sep 2009 01:34:35 +0100, andrew cooke <andrew at acooke.org>
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090924/5f14be97/attachment.html>


More information about the Python-list mailing list