1

I am trying to threading to call a function with args, but the Syntax I use says I am using to many args... but 2 are needed to are given... so why?

import threading
import time

class Baab():

    def finc(phrase):
        time.sleep(3)
        print(phrase)

    def fenc():
        time.sleep("last")

    def fanc(ophrase):
        print(ophrase)


def func(phrase, ophrase):
    b = Baab()
    b.fanc(ophrase)
    b.finc(phrase)
    b.fenc()

th = threading.Thread(target=func, args=("baba", "lol"))
th.start()
time.sleep(1)
print("second")   
Tknoobs
  • 169
  • 10

1 Answers1

2

The class methods expect a self attribute explicitly.

Try changing your class method as below:

class Baab():

    def finc(self, phrase):
        time.sleep(3)
        print(phrase)

    def fenc(self):
        time.sleep("last")

    def fanc(self, ophrase):
        print(ophrase)
Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
  • Ok... so I had a class where I was taking a function from. And there I did not needed the self parameter. So is it right that I only need the self when I call the function specifically trough its class... correct? – Tknoobs Jan 22 '21 at 10:24
  • may be you are talking about the static methods in Python: https://stackoverflow.com/questions/735975/static-methods-in-python. – Krishna Chaurasia Jan 22 '21 at 10:27