Re: Default method arguments
bruno at modulix wrote:[color=blue]
> Another solution to this is the use of a 'marker' object and identity[/color]
test:[color=blue]
>
> _marker = []
> class A(object):
> def __init__(self, n):
> self.data =n
> def f(self, x = _marker):
> if x is _marker:
> x = self.data
> print x[/color]
I'll add my 2 cents to the mix:
default = object()
class A(object):
def __init__(self, n):
self.data = n
def f(self, x=default):
if x is default:
x = self.data
print x
--
Benji York
bruno at modulix wrote:[color=blue]
> Another solution to this is the use of a 'marker' object and identity[/color]
test:[color=blue]
>
> _marker = []
> class A(object):
> def __init__(self, n):
> self.data =n
> def f(self, x = _marker):
> if x is _marker:
> x = self.data
> print x[/color]
I'll add my 2 cents to the mix:
default = object()
class A(object):
def __init__(self, n):
self.data = n
def f(self, x=default):
if x is default:
x = self.data
print x
--
Benji York
Comment