Last active
August 29, 2015 14:08
-
-
Save dhermes/cade46bcd52a70ed9228 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): | |
... bar = None | |
... def __fu(self, bar): | |
... self.bar = bar | |
... def public_fu(self, bar): | |
... self.__fu(bar) | |
... | |
>>> a = A() | |
>>> print (a, a.bar) | |
(<__main__.A object at 0x7fd5d0274810>, None) | |
>>> a.public_fu(10) | |
>>> print (a, a.bar) | |
(<__main__.A object at 0x7fd5d0274810>, 10) | |
>>> | |
>>> | |
>>> class B(A): | |
... rebar = None | |
... baz = None | |
... def _A__fu(self, bar): | |
... super(B, self)._A__fu(bar) | |
... self.rebar = 'Python hates me' | |
... def __fu(self, bar): | |
... raise ValueError((bar, 'sad')) | |
... def public_fu(self, bar, baz): | |
... super(B, self).public_fu(bar) | |
... self.baz = baz | |
... | |
>>> | |
>>> b = B() | |
>>> print (b, b.bar, b.baz, b.rebar) | |
(<__main__.B object at 0x7fd5d0274950>, None, None, None) | |
>>> b.public_fu(100, 111) | |
>>> print (b, b.bar, b.baz, b.rebar) | |
(<__main__.B object at 0x7fd5d0274950>, 100, 111, 'Python hates me') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment