Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.