Skip to content

Instantly share code, notes, and snippets.

@mgedmin

mgedmin/slots.py

Created Aug 13, 2018
Embed
What would you like to do?
Python 2.7.14 (default, Sep 23 2017, 22:06:14)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Wat(object):
... __slots__ = ('a', 'b')
... a = 42
...
>>> x = Wat()
>>> x.a
42
>>> x.b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: b
>>> Wat.a
42
>>> Wat.b
<member 'b' of 'Wat' objects>
>>> type(Wat.b)
<type 'member_descriptor'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment