Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)
Ron Adam
rrr at ronadam.com
Tue Aug 16 14:31:05 EDT 2005
Antoon Pardon wrote:
> I disagree here. The problem with "global", at least how it is
> implemented in python, is that you only have access to module
> scope and not to intermediate scopes.
>
> I also think there is another possibility. Use a symbol to mark
> the previous scope. e.g. x would be the variable in local scope.
> @.x would be the variable one scope up. @. at .x would be the
> variable two scopes up etc.
Looks like what you want is easier introspection and the ability to get
the parent scope from it in a simple way. Maybe something like a
builtin '__self__' name that contains the information, then a possible
short 'sugar' method to access it. '__self__.__parent__', would become
@ in your example and '__self__.__perent__.__self__.__parent__' could
become @. at .
Somthing other than '@' would be better I think. A bare leading '.' is
another possiblity. Then '..x' would be the x two scopes up.
This isn't the same as globals. Globals work the way they do because if
they weren't automatically visible to all objects in a module you
wouldn't be able to access any builtin functions or class's without
declaring them as global (or importing them) in every function or class
that uses them.
Cheers,
Ron
More information about the Python-list
mailing list