如何从函数定义中访问内部 class 的常量?
How can I access a constant of an inner class from a function definition?
我有 class sprite
和内部 class type
。
class sprite:
class type:
ThisValue = 10
OtherValue = 22
def __init__(self, type = sprite.type.ThisValue):
self.type = type
当我尝试这个时,它说名称 sprite
未定义;错误抛出在 def __init__()
行。如何在函数定义中访问 ThisValue
? type
class 有更好的写法吗?
你只需要
def __init__(self, type = type.ThisValue):
我有 class sprite
和内部 class type
。
class sprite:
class type:
ThisValue = 10
OtherValue = 22
def __init__(self, type = sprite.type.ThisValue):
self.type = type
当我尝试这个时,它说名称 sprite
未定义;错误抛出在 def __init__()
行。如何在函数定义中访问 ThisValue
? type
class 有更好的写法吗?
你只需要
def __init__(self, type = type.ThisValue):