Python - what's your conventions to declare your attributes in a class ?
Posted
by
SeyZ
on Stack Overflow
See other posts from Stack Overflow
or by SeyZ
Published on 2010-12-30T10:39:53Z
Indexed on
2010/12/30
10:54 UTC
Read the original article
Hit count: 217
Hello,
In Python, I can declare attributes all over the class. For example :
class Foo:
def __init__(self):
self.a = 0
def foo(self):
self.b = 0
It's difficult to retrieve all attributes in my class when I have a big class with a lot of attributes.
Is it better to have the following code (a) or the next following code (b) :
a) Here, it's difficult to locate all attributes :
class Foo:
def __init__(self):
foo_1()
foo_2()
def foo_1(self):
self.a = 0
self.b = 0
def foo_2(self):
self.c = 0
b) Here, it's easy to locate all attributes but is it beautiful ?
class Foo:
def __init__(self):
(self.a, self.b) = foo_1()
self.c = foo_2()
def foo_1(self):
a = 0
b = 0
return (a, b)
def foo_2(self):
c = 0
return c
In a nutshell, what is your conventions to declare your attributes in a class ?
© Stack Overflow or respective owner