Re: namespace question

From: Bengt Richter (bokr_at_oz.net)
Date: 09/04/04


Date: 4 Sep 2004 19:31:56 GMT

On Fri, 3 Sep 2004 08:11:35 +0200, aleaxit@yahoo.com (Alex Martelli) wrote:

>Elaine Jackson <elainejackson7355@home.com> wrote:
>
>> I would like to be able to write a function f, which will live in a module M,
>> and will call a function g, such that, when f is imported from M into the
>> interpreter, and invoked there, its invokation of g will return the
>> interpreter's global namespace. Is there a way to do this and, if so, how?
>> Muchas gracias for any and all assistance.
>
>There is no "interpreter global namespace". If you mean the namespace
>of the calling module (which could be the interactive session's __main__
>if that's who did the importing) you can get there via sys._getframe --
>it's meant for debugging purposes (note the leading underscore) but it
>will work. If you mean the namespace of __main__ (which could be the
>interactive session if there is one) you can get the __main__ module
>anywhere as sys.modules['__main__'] and a vars call around that will
>give the module's dictionary (which is, I assume, what you mean by
>namespace).
>
This brings up the question of standard terminology (e.g. for namespace).
If one googles for python glossary, the top references are mostly

    http://manatee.mojam.com/python-glossary

which seems not to have caught on so far (mea culpa too, since it takes volunteers ;-/ ).

Anyway, my take on 'namespace' is a name->value mapping. I.e., pretty abstract.
Then follows a discussion of various python mechanisms that do that (whether via
a single dict's d[name] mapping or the infinite d.get(name, default) mapping,
or the mapping implicit in the search, e.g., for a bare name using a function's
local name lookup rules (local, closure, global, builtin) -- not to mention the
mapping names undergo when used as attribute names in various ways.

Compared to other languages, python's name spaces (in my sense) seem to have
evolved interestingly ;-) I am wondering whether the future holds a more unified
model of namespaces and their access mechanisms, so most inspect and sys._getframe
name access hacks will be obviated.

Re defintions, perhaps it is time to reinvigorate Skip's wiki or something like that?

There was an interesting thread re improving python doc functionality at

http://mail.python.org/pipermail/python-list/2004-May/219682.html

An online extension of help() maybe taking a syntax clue from google ,like

    help('define:xxx')

might be an interesting hook into a glossary of definitions.

Regards,
Bengt Richter



Relevant Pages

  • Re: why cannot assign to function call
    ... and I had to think long and hard about what you were saying, Mark, in ... to understand Python programs, and I think I may have figured out why. ... this case the mapping being changed is the local function's namespace ... We can't affect the caller's namespace mapping, ...
    (comp.lang.python)
  • Re: why cannot assign to function call
    ... I am an experienced Python programmer, ... order to understand how it applied to Python. ... this case the mapping being changed is the local function's namespace ... We can't affect the caller's namespace mapping, ...
    (comp.lang.python)
  • Re: namespace problem
    ... > Hang on - is Mapping a class as well as a namespace, ... Mapping is a namespace of b2b.Server.Business and Facility is a ... with using declarations it shouldn't be a problem - just ...
    (microsoft.public.dotnet.languages.csharp)
  • web reference transform map
    ... I'm trying to use an XML message that I get back from a SOAP call as the source ... schema in a mapping which seems to work fine until I try to compile at which ... namespace 'BiztalkProcess' ...
    (microsoft.public.biztalk.general)
  • Re: Axis 1.x: Java2WSDL namespace options
    ... -p [mapping from package to namespace] ... Will they affect the required deployment ... It is usually a very good thing to do the mapping. ...
    (comp.lang.java.programmer)