python对象()不接受任何参数错误
我不敢相信这实际上是个问题,但我一直在尝试调试这个错误,结果一无所获。我肯定我错过了一些非常简单的东西,因为这看起来太傻了python对象()不接受任何参数错误,python,Python,我不敢相信这实际上是个问题,但我一直在尝试调试这个错误,结果一无所获。我肯定我错过了一些非常简单的东西,因为这看起来太傻了 import Experiences, Places, Countries class Experience(object): def make_place(self, place): addr = place["address"] addr = Places.ttypes.Address(addr["street"], addr[
import Experiences, Places, Countries
class Experience(object):
def make_place(self, place):
addr = place["address"]
addr = Places.ttypes.Address(addr["street"], addr["city"], addr["state"], Countries.ttypes._NAMES_TO_VALUES[addr["country"]], addr["zipcode"])
ll = Geocoder.geocode(addr["street"]+", "+addr["city"]+", "+addr["state"]+" "+addr["zipcode"])
place["location"] = Places.ttypes.Location(ll[0].coordinates[0], ll[0].coordinates[1])
def __init__(self, exp_dict):
exp_dict["datetimeInterval"] = Experiences.ttypes.DateTimeInterval(remove(exp_dict, "startTime"), remove(exp_dict, "endTime"))
exp_dict["type"] = Experiences.ttypes.ExperienceType.OPEN
exp_dict["place"] = self.make_place(exp_dict["place"])
self.obj = Experiences.ttypes.Experience(**exp_dict)
@client.request
@client.catchClientException
def addExperience(thrift, access_token, exp_dict):
experience = Experience(exp_dict)
return thrift.client.addExperience(thrift.CLIENT_KEY, access_token, experience.obj)
(与addExperience相对应的两个修饰符是,因为这是在声明其类的文件之外定义的。)
我得到的错误是:
experience = Experience(exp_dict)
TypeError: object() takes no parameters
这对我来说没有任何意义,因为我清楚地向init函数声明了第二个参数。任何帮助都会很棒
Traceback (most recent call last):
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/phil/Hangify/hy-frontend-server/env/lib/python2.7/site- packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/phil/Hangify/hy-frontend-server/hangify/session.py", line 22, in check_login
return f()
File "/Users/phil/Hangify/hy-frontend-server/hangify/handlers/create.py", line 31, in Handle
res = exp.addExperience(hangify.thrift_interface, access_token, experience)
File "/Users/phil/Hangify/hy-frontend-server/hangify/client/__init__.py", line 22, in decorator
obj = func(client, *args, **kwargs)
File "/Users/phil/Hangify/hy-frontend-server/hangify/client/__init__.py", line 30, in decorator
return func(*args, **kwargs)
File "/Users/phil/Hangify/hy-frontend-server/hangify/client/exp.py", line 39, in addExperience
experience = Experience(exp_dict)
TypeError: object() takes no parameters
下面是Experience.mro()-它表示类Experience的正确模块位置:
[<class 'hangify.client.exp.Experience'>, <type 'object'>]
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'make_place']
您混合了制表符和空格
\uuuu init\uuuu
实际上是嵌套在另一个方法中定义的,因此您的类没有自己的\uuuuu init\uuuu
方法,而是继承对象。在记事本中打开代码,而不是在使用任何编辑器,您将看到Python的选项卡处理规则看到的代码
这就是为什么你不应该混合标签和空格。坚持这样或那样。建议使用空格。您必须在每次点击时按两次和(_)键,它必须看起来像:
__init__
我为此挣扎了一会儿。\uuuu init\uuuu
的愚蠢规则。两个“_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。顺便说一句,我输入了\uuuuu int\uuu而不是\uuuu init\uuu
我认为,在许多输入错误的情况下,我使用的IDE(IntelliJ)会将颜色更改为函数定义的默认设置。但是,在我的例子中,作为另一种dunder/magic方法,颜色与IDE为\uuuuuu init\uuuuuu显示的颜色相同(默认预定义项定义颜色),这花了我一段时间才发现缺少的我什么是经验
什么是经验。t类型
?经验很重要,但我认为这与此无关。例如,当我从继承链中删除对象时,错误变成了TypeError:这个构造函数不带参数
@phileaton:什么类的类方法?我怀疑经验(exp_dict)
并不是指你认为的课程。您能否创建一个自包含的示例来演示该问题?您能否显示异常的完整回溯?除非Experience
在包含addExperience
的任何名称空间中被重新定义,否则该异常没有意义。问题包含正确的\uuuuuu init\uuuuu
。之所以出现此错误,是因为在我的情况下我草率地只编写了\uuuu init()
-多么蹩脚的错误:D自视1h vs SO 3m来解决问题:Plol,我也犯了同样的错误,但找不到它。您的评论帮助我交叉检查了我使用的默认方法。谢谢:)