Skip to content

Instantly share code, notes, and snippets.

@jmemich
Last active September 7, 2015 11:39
Show Gist options
  • Save jmemich/8a1281788409cdeeb5ae to your computer and use it in GitHub Desktop.
Save jmemich/8a1281788409cdeeb5ae to your computer and use it in GitHub Desktop.
Quick n easy example of mutability mess
class MutableClass():
def __init__(self):
self.thing = [] # mutable
self.nonething = None
def fn(self, new):
self.thing.append(new)
self.nonething = new
m, m2 = MutableClass(), MutableClass()
m.fn('first')
m.fn('second')
# something missing...
# >>> ['first', 'second'] second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment