python name spaces

Daniel Ortmann dortmann at lsil.com
Sun Mar 10 21:11:49 EST 2002


Hello,

As a Perl user who has switched to Python for all of the standard
reasons ...

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.

Arbitrarily creating variables and subroutines with different scopes.
(The actual example seems silly, but really isn't.)

1) Can such name space manipulation be done in Python?
2) What about the creation of substantial subroutine closures?

Thanks in advance for any help!

-- 
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