假设我有这个:
class Test():
def __init__(self, number):
self.number = number
await self.TestPrint()
async def TestPrint(self):
print(self.number)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这不起作用,因为__init__不是async,而且我无法调用await该函数。
我希望能够在假设我想维护这个函数 async 的情况TestPrint下运行。__init__
我还希望它与类之外的任何其他内容(其他函数、其他类、main 等)无关。