Created
August 13, 2010 09:35
-
-
Save miku/522619 to your computer and use it in GitHub Desktop.
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
class A(object): | |
active = True | |
def about_me(self): | |
return A.active | |
def am_i_active(self): | |
if self.__class__.active: | |
print 'Yes, sir!' | |
else: | |
print 'Nope.' | |
class B(A): | |
def about_me(self): | |
return B.active | |
if __name__ == '__main__': | |
a = A() | |
b = B() | |
print a.about_me() | |
print b.about_me() | |
print '----' | |
A.active = True | |
B.active = False | |
print a.about_me() | |
print b.about_me() | |
print '----' | |
a.am_i_active() | |
b.am_i_active() | |
# True | |
# True | |
# ---- | |
# True | |
# False | |
# ---- | |
# Yes, sir! | |
# Nope. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment