Created
June 30, 2016 16:14
-
-
Save kitsuyui/06a1eee2ae93f5832ef7d0774ef53346 to your computer and use it in GitHub Desktop.
Python 3.4.3 と 3.4.4 の間で namedtuple の挙動が微妙に変わっていた件 ref: http://qiita.com/kitsuyui/items/871adfe855127483245f
This file contains hidden or 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 collections import namedtuple | |
X = namedtuple('X', ('a', 'b')) | |
class Y(X): | |
__slots__ = () | |
class Z(X): | |
# __slots__ = () を忘れた場合 | |
pass | |
x = X(1, 2) | |
y = Y(1, 2) | |
z = Z(1, 2) | |
print(x._asdict()) | |
print(hasattr(x, '__dict__')) | |
print(y._asdict()) | |
print(hasattr(y, '__dict__')) | |
print(z._asdict()) | |
print(hasattr(z, '__dict__')) | |
This file contains hidden or 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
OrderedDict([('a', 1), ('b', 2)]) | |
True | |
OrderedDict([('a', 1), ('b', 2)]) | |
True | |
{} | |
True |
This file contains hidden or 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
OrderedDict([('a', 1), ('b', 2)]) | |
False | |
OrderedDict([('a', 1), ('b', 2)]) | |
False | |
OrderedDict([('a', 1), ('b', 2)]) | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment