Skip to content

Instantly share code, notes, and snippets.

@forslund
Created August 22, 2019 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forslund/b1c78d8d90e8e2212a866d69830120fe to your computer and use it in GitHub Desktop.
Save forslund/b1c78d8d90e8e2212a866d69830120fe to your computer and use it in GitHub Desktop.
Python class variables test
class C:
class_var = None
def __init__(self):
if self.class_var is None:
self.class_var = [1]
print('Creating new instance')
else:
print('Appending to existing')
self.class_var.append(1)
c1 = C()
c2 = C()
c3 = C()
$python3 bad_class_var.py
Creating new instance
Creating new instance
Creating new instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment