我正在尝试转换一个旧的库,它将名为snakefood的依赖项映射到python3。我有两个部分我不知道该替代什么,因为我找不到关于这两个函数的文档-from compiler.ast import Discard, Const
我似乎在python3的ast
库中找不到等价的。以下是来自Python 2的函数调用,请参见此处在isinstance()
调用中使用的两个函数:
def default(self, node):
pragma = None
if self.recent:
if isinstance(node, Discard):
children = node.getChildren()
if len(children) == 1 and isinstance(children[0], Const):
const_node = children[0]
pragma = const_node.value
self.accept_imports(pragma)
很抱歉,我不明白这些东西,我刚知道AST调用试图使用这个库。非常感谢。在
Discard
(花了我一段时间才弄清楚它是干什么的)现在是Expr
(尽管这比以前包含了更多的内容)我从编译器的源代码得到这个提示/代码生成.py公司名称:
Const
已被几种不同的类型所取代,这些类型代表各种常量,特别是Num
,Str
,JoinedStr
,以及其他一些类型。所有ast类型的文档can be found here。在相关问题 更多 >
编程相关推荐