python name spaces

Daniel Ortmann dortmann at lsil.com
Mon Mar 11 10:46:16 EST 2002


Hans Nowak <wurmy at earthlink.net> writes:

> Daniel Ortmann wrote:

> > I must admit I am frustrated by Python's seeming lack of powerful
> > name space support.  For example, in Perl I can do something like
> > this,

> >     our $b = "...b";
> > 
> >     {
> >         my $a = "...a";
> >         our $f = sub { print $a, "\n" };
> >         our $g = sub { $a = "foo" }
> >     }
> > 
> >     $f->()
> >     $g->()
> > 
> >     # prints ...a, followed by foo.
> >     # the "$a" variable is ONLY seen by the unnamed $f and $g
> >     # subroutines.

> I don't know much about Perl, but this seems a bit like a closure like
> Lisp and Scheme have them.

Yes!  (I was avoiding buzzwords.:-)

> Python namespaces don't work like this. If you want a variable to be
> only visible by a few functions, and shared by those functions, the
> Pythonic solution would be, writing a class.

But must I _name_ everything?

What if I want to build a closure, apply it several times locally, and
then throw it away?  Am I correct that Python "lambda"s, in name only,
resemble Scheme lambdas?

(I posted since I saw no PEP addressing these issues.)

-- 
Daniel Ortmann, LSI Logic
3425 40th Av NW, Suite 200, Rochester, MN 55901
dortmann at lsil.com / 507.529.3887 (w) / 535.3887 (int)
ortmann at isl.net   / 507.288.7732 (h)



More information about the Python-list mailing list