Last active
September 7, 2015 11:39
-
-
Save jmemich/8a1281788409cdeeb5ae to your computer and use it in GitHub Desktop.
Quick n easy example of mutability mess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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