<分区> 分区>
这就是我正在做的:
class D(float):
def __init__(self, name):
self._name = name
print name
但是当我尝试初始化 D 类型的对象时:
d = D('aaa')
我收到这个错误:
Traceback (most recent call last):
File "/home/user/untitled1.py", line 22, in <module>
d = D('aaa')
ValueError: could not convert string to float: aaa
为什么?我不是在初始化一个 float ,只是设置一个名称。我没有调用 float 的 __init__。
