Skip to content

Instantly share code, notes, and snippets.

@lig
Created October 5, 2015 01:48
Show Gist options
  • Save lig/795867d826ec5e64bdbf to your computer and use it in GitHub Desktop.
Save lig/795867d826ec5e64bdbf to your computer and use it in GitHub Desktop.
Python 3.4.2 (default, Jul 9 2015, 17:24:30)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __init__(self):
... self.__foo = 'bar'
...
>>> class B(A):
... def foo(self):
... print(self._A__foo)
...
>>> b = B()
>>> b.foo()
bar
>>> from collections import OrderedDict
>>> class MyDict(OrderedDict):
... def __setitem__(self, *args, **kwargs):
... print(self._OrderedDict__root)
... OrderedDict.__setitem__(self, *args, **kwargs)
...
>>> md = MyDict({'a': 1})
<collections._Link object at 0x7f0398a79b88>
Python 3.5.0 (default, Sep 26 2015, 14:59:25)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __init__(self):
... self.__foo = 'bar'
...
>>> class B(A):
... def foo(self):
... print(self._A__foo)
...
>>> b = B()
>>> b.foo()
bar
>>> from collections import OrderedDict
>>> class MyDict(OrderedDict):
... def __setitem__(self, *args, **kwargs):
... print(self._OrderedDict__root)
... OrderedDict.__setitem__(self, *args, **kwargs)
...
>>> md = MyDict({'a': 1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __setitem__
AttributeError: 'MyDict' object has no attribute '_OrderedDict__root'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment