Skip to content

Instantly share code, notes, and snippets.

@grihabor
Last active October 31, 2017 22:41
Show Gist options
  • Save grihabor/2fd02d1c80c8f13289c8596489594455 to your computer and use it in GitHub Desktop.
Save grihabor/2fd02d1c80c8f13289c8596489594455 to your computer and use it in GitHub Desktop.
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'
x.run('b')
print(x.a, x.b, x.c)
#|a b c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment