Lexical scope: converting Perl to Python
I V
ivlenin at gmail.com
Sat Jun 13 07:48:28 EDT 2009
On Fri, 12 Jun 2009 22:02:53 -0700, Andrew Savige wrote:
> Notice that this code uses Perl's lexical scope to hide the
> %private_hash variable, but not the public_fn() function.
You might try:
def public_fn(param):
private_hash = publicfn.private_hash
return private_hash[param]
public_fn.private_hash = {'A':42, 'B':69}
(You don't have to assign public_fn.private_hash to a local variable, but
you might want to, to avoid extra typing, if you refer to private_hash
more than a couple of times in the function).
More information about the Python-list
mailing list