Skip to content

Instantly share code, notes, and snippets.

@mattjmorrison
Created April 4, 2012 13:05
Show Gist options
  • Save mattjmorrison/2300933 to your computer and use it in GitHub Desktop.
Save mattjmorrison/2300933 to your computer and use it in GitHub Desktop.
Python: Roll your own OO
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