[Python-Dev] More flexible namespaces.

Mark Hammond MHammond at skippinet.com.au
Fri Apr 30 04:40:09 CEST 1999


Here is a bit of an idea that I first came up with some years ago.  Guido's
response at the time was "sounds reasonable as long as we dont slow the
normal case down".

To cut a long story short, I would like eval and exec to be capable of
working with arbitrary mapping objects rather than only dictionaries.  The
general idea is that I can provide a class with mapping semantics, and pass
this to exec/eval.

This would give us 2 seriously cool features (that I want <wink>), should
anyone decide to write code that enables them:

* Case insensitive namespaces.  This would be very cool for COM, and as far
as I know would please the Alice people.  May open up more embedding
opportunities that are lost if people feel strongly about this issue.

* Dynamic name lookups.  At the moment, dynamic attribute lookups are
simple, but dynamic name lookups are hard.  If I execute code "print foo",
foo _must_ pre-exist in the namespace.  There is no reasonable way I can
some up with so that I can fetch "foo" as it is requested (raising the
NameError if necessary).  This would also be very cool for some of the COM
work - particularly Active Scripting.

Of course, these would not be enabled by standard Python, but would allow
people to create flexible execution environments that suit their purpose.

Any comments on this?  Is it a dumb idea?  Anyone have a feel for how deep
these changes would cut?  Its not something I want to happen soon, but it
does seem a reasonable mechanism that can provide very flexible
solutions...

Mark.





More information about the Python-Dev mailing list