我不能在一个类中使用self。看起来装饰器后的函数的数据是第一个参数。
例子:
import socketio
import random
sio = socketio.Client()
class Test:
def __init__(self):
self.uid = random.randint(0, 10)
@sio.on('test')
def test(self, message):
test_message = str(self.uid) + message
print(test_message)
@staticmethod
def run():
sio.connect('ws://127.0.0.1:5000')
sio.wait()
if __name__ == '__main__':
test = Test()
test.run()
错误:</p>
TypeError: test() missing 1 required positional argument: 'message'