Default method arguments
Mike Meyer
mwm at mired.org
Tue Nov 15 15:33:32 EST 2005
gregory.petrosyan at gmail.com writes:
> Hello everybody!
> I have little problem:
>
> class A:
> def __init__(self, n):
> self.data = n
> def f(self, x = ????)
> print x
>
> All I want is to make self.data the default argument for self.f(). (I
> want to use 'A' class as following :
Store your default value in a container, and test for it:
class A:
_data = [None]
def __init__(self, n):
self._data = [n]
def f(self, x = _data):
if x is self._data:
x = x[0]
print x
There are lots of variations on this theme.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list