Skip to content

Instantly share code, notes, and snippets.

View grihabor's full-sized avatar

Gregory Borodin grihabor

View GitHub Profile
@grihabor
grihabor / attribute-definition-placement-good.py
Last active October 31, 2017 22:41
Define all class attributes inside the constructor
class X:
def __init__(self):
self.a = 'a'
self.b = None
self.c = None
def run(self, b)
self.b = b
x = X()
x.c = 'c'
@grihabor
grihabor / attribute-definition-placement-bad.py
Last active November 1, 2017 19:50
Define attributes all over the code on the fly #bad
class X:
def __init__(self):
self.a = 'a'
def run(self, b)
self.b = 'b'
x = X()
x.c = 'c'
x.run('b')
print(x.a, x.b, x.c)