相关疑难解决方法(0)

输入提示:解决循环依赖

以下产生NameError: name 'Client' is not defined.我该如何解决?

class Server():
    def register_client(self, client: Client)
        pass


class Client():
    def __init__(self, server: Server):
        server.register_client(self)
Run Code Online (Sandbox Code Playgroud)

python type-hinting python-3.5

41
推荐指数
2
解决办法
5548
查看次数

Python相互依赖的类(循环依赖)

我搜索了很多,但我发现的主要是python中递归编程的例子.所以这里有一个问题:

我怎样才能做到这一点?

class A:
    b = B()

class B:
    a = A()
Run Code Online (Sandbox Code Playgroud)

python class circular-dependency

16
推荐指数
1
解决办法
2365
查看次数