2012-08-08 94 views
0

我是编程python的新手。我在Linux上建立了Beremiz程序,我得到了这个错误。Python为语法

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的构建。什么是问题? 谢谢大家。

+2

哪个Python版本您使用的?您的代码可能会使用较旧版本的Python不支持的一些更新的语法。 – 2012-08-08 01:50:55

+0

这对Python 3.x运行良好,请确保您使用的软件的设计版本。 – Kudu 2012-08-08 02:07:09

回答

3

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

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

connectors = dict((name, _GetLocalConnectorClassFactory(name)) 
        for name in listdir(_base_path) 
         if path.isdir(path.join(_base_path, name)) 
          and not name.startswith("__")) 
+0

这是工作。非常感谢你。 :) – user1583382 2012-08-09 02:48:03