Exposing members or make them private in Python?
Posted
by deamon
on Stack Overflow
See other posts from Stack Overflow
or by deamon
Published on 2010-04-29T14:33:37Z
Indexed on
2010/04/29
14:37 UTC
Read the original article
Hit count: 219
Is there a general convention about exposing members in Python classes? I know that this is a case of "it depends", but maybe there is a rule of thumb.
Private member:
class Node:
def __init__(self):
self.__childs = []
def add_childs(self, *args):
self.__childs += args
node = Node()
node.add_childs("one", "two")
Public member:
class Node2:
def __init__(self):
self.childs = []
node2 = Node2()
node2.childs += "one", "two"
© Stack Overflow or respective owner