Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created September 27, 2012 05:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ChimeraCoder/3792248 to your computer and use it in GitHub Desktop.
Python Prototypical Inheritance Example
from __future__ import print_function
class Foo(object):
apple = "red"
def __init__(self, banana):
self.banana = banana
tmp = Foo("yellow")
print(tmp.apple)
print(tmp.banana)
print(tmp.carrot)
'''
Output:
red
yellow
Traceback (most recent call last):
File "PythonRebindings.py", line 15, in <module>
print(tmp.carrot)
AttributeError: 'Foo' object has no attribute 'carrot'
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment