Python 将参数线程化到多个参数时出现错误?
我试图通过线程来调用带有参数的函数,但我使用的语法表示我正在使用许多参数。。。但是需要2个来表示。。。那为什么呢Python 将参数线程化到多个参数时出现错误?,python,multithreading,time,Python,Multithreading,Time,我试图通过线程来调用带有参数的函数,但我使用的语法表示我正在使用许多参数。。。但是需要2个来表示。。。那为什么呢 import threading import time class Baab(): def finc(phrase): time.sleep(3) print(phrase) def fenc(): time.sleep("last") def fanc(ophrase):
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")
类方法需要显式的self属性 尝试按以下方式更改您的类方法:
class Baab():
def finc(self, phrase):
time.sleep(3)
print(phrase)
def fenc(self):
time.sleep("last")
def fanc(self, ophrase):
print(ophrase)
好啊所以我上了一节课,从中我得到了一个函数。在那里,我不需要self参数。所以当我通过类调用函数时,我只需要self,这对吗。。。正确吗?您可能正在谈论Python中的静态方法:。