Modifying access to local variables
Boris Boutillier
Bobox at netcourrier.com
Tue Jan 8 10:27:57 EST 2002
Hi all,
I'm practicing python for a while and had a question, I looked in this
newsgroup but didn't find something helpful already posted so I give
it here :
What I wanna do is be able to write without error the following thing
:
def foo():
x = z
z isn't define anywhere (not a global variable) and I want it to be of
special class, say Myclass.
So what I want the code to mean is the following :
def foo():
z = MyClass()
x = z
But this line of declaration is useless as all the variables I'll use
in the function will be MyClass object. Is there a way to avoid
declarations of variables in function (in my case, I'll have more than
a hundred ones).
I was thinking about something redifining a __getattr__ function
associated with local variables but I don't know if it is possible or
if there is another way to do it. The main idea is to avoid hundreds
of declarations lines.
Hope I made me clear, and thanks for answers.
Boris
More information about the Python-list
mailing list