[Python-ideas] Interrogate alternate namespace keyword and concept
prozacgod at gmail.com
Fri Aug 14 08:22:07 CEST 2009
A while back i had learned about the 'with' statement and at first I naively
thought that it worked similarly to a with statement I was familiar with,
from delphi/pascal - obviously it doesn't and I was instantly hit with the
idea of how useful it would be to have a keyword that could use a namespace
from an object, hitting the familiar __getattr__ functions and related.
the keyword I proposed would be 'interrogate' (which is rather long, could
use another one like 'using' or something) but.. thats not really important
to me, the idea is, so
self.x = 42
foo = test()
bar = test()
x = 33
bar.x = 22
interrogate foo, bar:
output is 42 since x is found inside of foo before bar, and locals would be
interrogated last, but a more usefull example would be ..
def __getattr__(self, name):
if len(name) == 1 and (ord(name) in range(ord('a'), ord('z'))) :
test_ns = test()
output is 97
using the above example lexical closures may be awkward to implement in the
language itself, this is a bit of a contrived example.. but.. eh..
# if I understand python enough, then I believe that when we enter this
block, and create variables, they go out of scope,
# and there are no exceptions to this rule, ever so .. in order to implement
mine obviously scope would be the same
# mechanism so I have oh_bother declared in the local namespace first
oh_bother = None
oh_bother = geronimo
output is 122
"Prozac may heal the mind, but friends can mend the soul"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas