Search code examples
pythonooptraceback

How come there is a TypeError in my Python code?


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

Solution

  • Two errors

    1) Your class doesn't have an __init__ function. Either add one, or use this instead:

    decayer = tasks.Decayer()
    

    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 ^:

    y = 2 ** x