mongoengine:SyntaxError:语法无效

时间:2014-08-16 03:13:58

标签: python mongodb pymongo mongoengine

我使用mongoengine时出错了,我不知道原因是什么?

这是我的无效语法错误:

Traceback (most recent call last):
...
  File "/home/mictadlo/.virtualenvs/unisnp/lib/python2.7/site-packages/mongoengine/document.py", line 4, in <module>
import pymongo
  File "pymongo.py", line 33
}
^
SyntaxError: invalid syntax

使用此代码:

from mongoengine import *

connect('dbtest')


class Test(Document):

 tag = StringField(required=True)
 tlists = ListField(EmbeddedDocumentField('Tlist'))


class Tlist(EmbeddedDocument):

 ref = StringField(required=True)


for i in [('test1', "a"), ('test2', "b"), ('test3', "c"), ('test1', "a"),
          ('test2', "b"), ('test3', "c")]:
    test = Test()
    test.tag = i[0]
    tlist = Tlist()
    tlist.ref = i[1]
    test.tlists.append(tlist)
    test.save()

我做错了什么?

2 个答案:

答案 0 :(得分:0)

我只是将内容复制并粘贴到ide中,现在就可以了。

答案 1 :(得分:0)

invalid syntax File "pymongo.py", line 33出现}错误。 我认为你现在改变它!所以请看pymongo.py

第33行中的错误