python name spaces
Hans Nowak
wurmy at earthlink.net
Mon Mar 11 00:50:14 EST 2002
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.
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.
HTH,
--
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
More information about the Python-list
mailing list