Created
September 27, 2012 04:52
-
-
Save ChimeraCoder/3792229 to your computer and use it in GitHub Desktop.
Python class rebinding example
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
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