Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: warnTime() missing 1 required positional argument: i

I have this code:

def warnTime(i):
  i += 1
  print(i)

t = Timer(20, warnTime)
t.start()

The rest of the code works just fine, but when it comes to this part, it raises the TypeError.

When I try to get the variable value it does the same thing.
When I try to do i = 0 before the function it just returns 0.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried calling the function with argument, like warnTime(0) or variable = warnTime(0), but it didn’t work.

>Solution :

Assuming you are using the Threading Timer, you’ll need to pass the initial value of i, change your code to:

from threading import Timer

def warnTime(i):
  i += 1
  print(i)

t = Timer(20, warnTime, args=[0])
t.start()

Try it online!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading