Getting rid of "self."
timr at probo.com
Sun Jan 9 09:05:51 CET 2005
BJörn Lindqvist <bjourne at gmail.com> wrote:
>I think it would be cool if you could refer to instance variables
>without prefixing with "self." I know noone else thinks like me so
>Python will never be changed, but maybe you can already do it with
>. s = ""
>. for var in sys._getframe(1).f_locals["self"].__dict__:
>. s += var + " = self." + var + "\n"
>. return s
>. def __init__(self):
>. self.hi = "yo"
>. def meth(self):
>. print hi
>.a = A()
>It works! exec(magic()) does the needed hi = self.hi.
self.hi = "yo"
hi = "baby"
a = A()
That's way too fragile to be useful.
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list