Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created September 27, 2012 04:52
Show Gist options
  • Save ChimeraCoder/3792229 to your computer and use it in GitHub Desktop.
Save ChimeraCoder/3792229 to your computer and use it in GitHub Desktop.
Python class rebinding example
from __future__ import print_function
class Foo(object):
apple = "red"
def __init__(self, banana):
self.banana = banana
Bar = Foo
tmp = Bar(2)
print("Temp: ", tmp)
print("Temp's apple: ", tmp.apple)
Foo = 9 #Foo is no longer callable
print("Temp's apple: ", tmp.apple)
print("What's the type of temp?", type(tmp))
'''
Running that will give you the following:
Temp: <__main__.Foo object at 0x7f117c1ee590>
Temp's apple: red
Temp's apple: red
What's the type of temp? <class '__main__.Foo'>
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment