[Python-ideas] Interrogate alternate namespace keyword and concept

Prozacgod prozacgod at gmail.com
Fri Aug 14 21:25:29 CEST 2009

The motivation came up in this thread on python-forum.org


My main motivation most likely is just that it would open up some very
interesting meta-programing or dynamic programming opportunities, variables
that exists entirely programmatically without the prefix of
object_instance.foo, surely just syntactical sugar to some (or even most) -
I have found it to be valuable syntax.  just like the current with statement
bypasses some syntactical nusances of try: except: .. this would bypass the
nusance of  inst.x inst.y inst.z ...

After posting last night I realized A pitfall of implementing this - would

interrogate(foo, bar):
  xylophone = 1024

using this reference - ..

__setattr__ has no current way to fall through, so foo would get the setattr
event, and not be able to allow interrogate to hand it to bar.

I posit that raising the AttributeError exception would be sufficient, for
the hand off to occur, and if foo, then bar both did it, then one of two
ways to handle it would be the current scope variables would get it, (eg it
would be __del__ after the end of the block) or putting the new variable in
the parent namespace, since it is somewhat assumed that locals would follow
after bar

On Fri, Aug 14, 2009 at 2:54 AM, Steven D'Aprano <steve at pearwood.info>wrote:

> On Fri, 14 Aug 2009 04:22:07 pm Prozacgod wrote:
> > 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.
> What is the motivation? Is it just to reduce typing?
> Being an ex-Pascal coder myself, I originally missed having a
> Pascal-like 'with' statement too. But now I'm not so sure it is needed.
> I know this proposal (under the name 'with') has been discussed before,
> but I can't find a PEP for it... ah, here you go, it was in the FAQs:
> http://www.python.org/doc/faq/general/#why-doesn-t-python-have-a-with-statement-for-attribute-assignments
> C-# doesn't have one either:
> http://msdn.microsoft.com/en-us/vcsharp/aa336816.aspx
> I don't think there are any problems with a Pascal-style 'with'
> statement that couldn't be overcome, but I don't think the benefit is
> great enough to create a new keyword for it. Can you explain in more
> detail why this proposed feature is useful?
> --
> Steven D'Aprano
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas


"Prozac may heal the mind, but friends can mend the soul"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090814/04c99b82/attachment.html>

More information about the Python-ideas mailing list