Python:“ yield from”产生语法错误

时间:2018-11-11 13:36:04

标签: python

我在Ubuntu 16.04上使用Gaston Frequent Subgraph Mining implementation by Njissen,并在Python 3.6.5和2.7.15rc1上都尝试过。执行程序时,我得到

Traceback (most recent call last):
  File "/home/elias/.local/bin/gaston", line 11, in <module>
    load_entry_point('gaston-py==0.1', 'console_scripts', 'gaston')()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
    return ep.load()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2343, in load
    return self.resolve()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2349, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/gaston.py", line 5, in <module>
    import gaston_py.factory as factory
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/factory.py", line 7, in <module>
    import gaston_py.embedding as embedding
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/embedding.py", line 70
    yield from _create_embedding_list(graph, visited, neighbor_id)
             ^
SyntaxError: invalid syntax

yield from _create_embedding_list(graph, visited, neighbor_id)

产生错误的代码块:

def _create_embedding_list(graph, visited, node_id):
    for edge_label, neighbor_label, neighbor_id in sorted(_neighbor_labels(graph, visited, node_id)):
        if (node_id, neighbor_id) not in visited:
            visited.add((node_id, neighbor_id))
            visited.add((neighbor_id, node_id)) # if graph is undirected

            yield node_id, (edge_label, neighbor_label)
            yield from _create_embedding_list(graph, visited, neighbor_id)

由于这是正式实施,因此我怀疑不兼容或类似问题。如何运行此代码?感谢您的任何建议!

1 个答案:

答案 0 :(得分:3)

如回溯所示,您正在Python 2.7中运行此代码。但是yield from是Python 3 3中引入的,并且在早期版本中不受支持。