gpt4 book ai didi

python - 在另一个类变量定义中引用类变量

转载 作者:太空狗 更新时间:2023-10-29 20:42:47 24 4
gpt4 key购买 nike

class SomeClass:
SOME_CONST = "hello"
SOME_OTHER_CONST = SomeClass.SOME_CONST + " world"

这行不通。

NameError: name 'SomeClass' is not defined

有没有办法在类中引用类?

最佳答案

你不需要类名

class SomeClass:
SOME_CONST = "hello"
SOME_OTHER_CONST = SOME_CONST + " world"

关于python - 在另一个类变量定义中引用类变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10039422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com