Passing data attributes as method parameters
Piet van Oostrum
piet at cs.uu.nl
Mon Apr 24 05:55:57 EDT 2006
>>>>> "Panos Laganakos" <panos.laganakos at gmail.com> (PL) wrote:
>PL> Thanks Ben.
>PL> What does it mean that they're statically bound?
It means that the default values are evaluated at definition time. At that
time there isn't a variable 'self' defined. It would only work if the
defaults would be evaluated at the time the method is called, but that's
not how Python works.
>PL> It seems weird that I'm not able to access variables in the class
>PL> namespace even though these attributes come into existance after class
>PL> instantiation.
What do you mean 'variables in the class namespace'? Which variable is in
the class namespace? Please note that you can access variables in the class
namespace:
class MyClass:
a = 10
b = 20
def my_method(self, param1=a, param2=b):
print param1, param2
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list