Last active
September 21, 2016 06:38
-
-
Save fy0/cb1a3847a1affee6338c75930df5c801 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(dict): | |
def __new__(cls): | |
ret = dict.__new__(cls) | |
ret.a = 1 | |
return ret | |
class B(A): | |
def __new__(cls, a): | |
print('A new', a) | |
#return _A.__new__(cls) # 注释掉这句,a.a则会报错 | |
return dict.__new__(cls) | |
def __init__(cls, a): pass # 若无这个,B(1) 也会报错,这也算是个问题 | |
a = B(1) | |
print(type(a)) | |
#print(a.a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment