擅长:python、mysql、java
<p>所以我在snakefood中做得更好,最后用AST重写了代码。
Snakefood仍然使用编译器,这是弃用的,比使用ast慢得多。在</p>
<p>结果很好,例如这是一个访客:</p>
<pre><code>from ast import parse, NodeVisitor
class ImportVisitor(NodeVisitor):
def __init__(self):
self.imported = set()
super(ImportVisitor, self).__init__()
def __str__(self):
return '\n'.join(x for x in self.imported)
def visit_Import(self, node):
for n in node.names:
self.imported.add(n.name)
#that we are using
def visit_ImportFrom(self, node):
self.imported.add(node.module)
</code></pre>
<p>可用于例如:</p>
^{pr2}$