我们可以在NamedTuple本身中使用NamedTuple作为字段吗?

时间:2019-10-21 08:17:24

标签: python namedtuple

我需要定义一个自定义数据结构(例如Exp),该字段可以具有与相同数据结构(即Exp)相同的字段,但使用起来却很困惑...

我在Python3中使用NamedTuple,但是在定义相同结构类型的字段时,出现错误。

end

这会产生如下错误:

from typing import NamedTuple

class Expression(NamedTuple):
    left: Expression
    right: Expression
    operator: str

exp = Expression(None, None, "AS")
print(exp)

0 个答案:

没有答案