Instance attributes vs method arguments
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Nov 25 06:04:29 EST 2008
On Tue, 25 Nov 2008 10:48:01 +0000, John O'Hagan wrote:
> On Tue, 25 Nov 2008, Marc 'BlackJack' Rintsch wrote:
>> On Tue, 25 Nov 2008 07:27:41 +0000, John O'Hagan wrote:
>> > 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
>> > […]
>>
>> The question is if `args.a`, `args.b`, …, are semantically part of the
>> state of the objects or not. Hard to tell in general.
>
> Would you mind elaborating a little on that first sentence?
Do `self.a`, `self.b`, …, define the state of a `Class_a` instance or
not? One can't answer that question without knowing the meaning of the
class and the attributes.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list