On Fri, 2011-02-04 at 13:08 -0800, Wanderer wrote:
> I want to give the option of changing attributes in a method or using
> the current values of the attributes as the default.
>
> class MyClass():
> """ my Class
> """
> def __init__(self):
> """ initialize
> """
> self.a = 3
> self.b = 4
>
> def MyMethod(self, a = self.a, b = self.b)
> """ My Method
> """
> self.a = a
> self.b = b
> DoSomething(a, b)
>
> The above doesn't work. Is there a way to make it work?
>
> Thanks
>
This doesn't work because you can't reference keyword arguments in the
keyword argument array. This will work:
class MyClass:
def __init__(self):
""" initialize
Really? These are the worst docstrings ever.
"""
self.a = 3
self.b = 4
def MyMethod(self, a=None, b=None)
if a is not None:
self.a = a
if b is not None:
self.b = b
DoSomething(a, b)
--
http://mail.python.org/mailman/listinfo/python-list