为什么我的 Python 代码中出现 TypeError?
from celery.task import Task
class Decayer(Task):
def calc_decay_value(self, x):
y = (1.0/(2^x))
return y
def calc_decay_time(self, x):
y = 2^x
return y
def run(self, d, **kwargs):
#do stuff.
return 0
>>> decayer = tasks.Decayer(r)
Traceback (most recent call last):
File "scanDecay.py", line 31, in <module>
decayer = tasks.Decayer(r)
TypeError: object.__new__() takes no parameters
from celery.task import Task
class Decayer(Task):
def calc_decay_value(self, x):
y = (1.0/(2^x))
return y
def calc_decay_time(self, x):
y = 2^x
return y
def run(self, d, **kwargs):
#do stuff.
return 0
>>> decayer = tasks.Decayer(r)
Traceback (most recent call last):
File "scanDecay.py", line 31, in <module>
decayer = tasks.Decayer(r)
TypeError: object.__new__() takes no parameters
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个错误
1) 你的类没有 __init__ 函数。要么加一,要么改用这个:
2) 您试图计算一个整数的浮点数次方,但
^
表示异或,不能用于浮点数。使用**
代替^
:Two errors
1) Your class doesn't have an
__init__
function. Either add one, or use this instead:2) You are trying to raise an integer to the power of a float, but
^
means xor and cannot be used on floats. Use**
instead of^
:该问题似乎是由于
decayer =tasks.Decayer(r)
调用和tasks.Decayer 未设计为接受参数,因为Task
没有定义__init__
方法可以取其中一个。The problem seems due to
decayer = tasks.Decayer(r)
call and tasks.Decayer is not designed to take a argument, becauseTask
does not define a__init__
method which can take one.