Instance attributes vs method arguments
John O'Hagan
research at johnohagan.com
Tue Nov 25 02:27:41 EST 2008
Is it better to do this:
class Class_a():
def __init__(self, args):
self.a = args.a
self.b = args.b
self.c = args.c
self.d = args.d
def method_ab(self):
return self.a + self.b
def method_cd(self):
return self.c + self.d
or this:
class Class_b():
def method_ab(self, args):
a = args.a
b = args.b
return a + b
def method_cd(self, args)
c = args.c
d = args.d
return c + d
?
Assuming we don't need access to the args from outside the class,
is there anything to be gained (or lost) by not initialising attributes that
won't be used unless particular methods are called?
Thanks,
John O'Hagan
More information about the Python-list
mailing list