Created
April 4, 2012 13:05
-
-
Save mattjmorrison/2300933 to your computer and use it in GitHub Desktop.
Python: Roll your own OO
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
def Module(): | |
module_state = {} | |
def Class(val): | |
def get_val(): | |
return val | |
class_state = {'get_val': get_val} | |
return class_state | |
module_state['Class'] = Class | |
return module_state | |
module = Module() | |
first_instance = module['Class']('a') | |
second_instance = module['Class']('b') | |
print first_instance['get_val']() | |
print second_instance['get_val']() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment