SyntaxError:字典中的语法无效

时间:2014-04-09 07:15:26

标签: python python-2.6

Traceback (most recent call last):
  File "./openerp-server", line 2, in <module>
    import openerp
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/__init__.py", line 70, in <module>
    import cli
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/cli/__init__.py", line 6, in <module>
    from openerp.modules import module
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/modules/__init__.py", line 27, in <module>
    from . import db, graph, loading, migration, module, registry
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/modules/graph.py", line 32, in <module>
    import openerp.osv as osv
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/osv/__init__.py", line 22, in <module>
    import osv
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/osv/osv.py", line 22, in <module>
    from openerp.osv.orm import except_orm, Model, TransientModel, AbstractModel
  File "/home/tiny/Desktop/openerp/server/trunk/openerp/osv/orm.py", line 2377
    groupby_dict = {gb['groupby']: gb for gb in annotated_groupbys}
                                        ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:1)

Dict comprehensions已添加到2.7版本的语言中。

所以你需要升级到Python 2.7。如果你坚持使用2.6,你可以使用

groupby_dict = dict((gb['groupby'], gb) for gb in annotated_groupbys)

答案 1 :(得分:1)

您必须使用

创建dict
dict((gb['groupby'], gb) for gb in annotated_groupbys)