Python For Grammar

时间:2012-08-08 01:46:16

标签: python

我是编程python的新手。我在Linux上构建了Beremiz程序,我收到了这个错误。

File "Beremiz.py", line 164, in <module>
    from ProjectController import ProjectController, MATIEC_ERROR_MODEL, ITEM_CONFNODE
  File "/DATA1/UTILITY/Beremiz/beremiz/ProjectController.py", line 16, in <module>
    import connectors
  File "/DATA1/UTILITY/Beremiz/beremiz/connectors/__init__.py", line 34
    for name in listdir(_base_path) 
      ^


connectors = {name:_GetLocalConnectorClassFactory(name)
                  for name in listdir(_base_path)
                      if path.isdir(path.join(_base_path, name))
                          and not name.startswith("__")}

这种语法不是python的构建。有什么问题? 谢谢大家。

1 个答案:

答案 0 :(得分:3)

您需要确保您的Python版本支持字典理解语法。这需要Python&gt; = 2.7或Python&gt; = 3.

否则你可以像这样修改代码:

connectors = dict((name, _GetLocalConnectorClassFactory(name))
                  for name in listdir(_base_path)
                      if path.isdir(path.join(_base_path, name))
                          and not name.startswith("__"))
相关问题