sunkezai 发表于 2017-5-8 12:38:49

TypeError: this constructor takes no arguments(Python 学习遇到的错误1)

第一个错误Traceback (most recent call last):File "<pyshell#8>", line 1, in <module>f = FooBar('wrong')
TypeError: this constructor takes no arguments  源码如下:

class FooBar:def _init_(self, value):self.somevar = value

  错误原因:
构造函数,是两个下划线,不是一个!




正确的代码如下:



class FooBar:def __init__(self, value):self.somevar = value




页: [1]
查看完整版本: TypeError: this constructor takes no arguments(Python 学习遇到的错误1)