我有
$ python test3.py
828288
Traceback (most recent call last):
File "test3.py", line 48, in <module>
test.pos = i[3],
File "/home/mic/.virtualenvs/test/lib/python2.7/site-packages/couchdb/mapping.py", line 105, in __set__
value = self._to_json(value)
File "/home/mic/.virtualenvs/test/lib/python2.7/site-packages/couchdb/mapping.py", line 112, in _to_json
return self._to_python(value)
TypeError: int() argument must be a string or a number, not 'tuple'
使用以下脚本和 couchdb-python (0.9):
from couchdb.mapping import Document, TextField, IntegerField, Mapping
from couchdb.mapping import DictField, ViewField, BooleanField, ListField
from couchdb import Server
# $ sudo systemctl start couchdb
# http://localhost:5984/_utils/
class Test(Document):
type = TextField() # "Test"
name = TextField() # "name"
sub_name = TextField() # "B01"
pos = IntegerField() # 828288
s_type = IntegerField() # 1
_id = IntegerField() # x_type = 7
chr = ListField(DictField(Mapping.build(
letter=TextField(), # C
no=IntegerField(), # 5
)))
server = Server()
db = server.create("test")
r = [["Test", "A", "B01", 828288, 1, 7, 'C', 5],
["Test", "A", "B01", 828288, 1, 7, 'T', 6],
["Test", "A", "B01", 171878, 3, 8, 'C', 5],
["Test", "A", "B01", 171878, 3, 8, 'T', 6],
["Test", "A", "B01", 871963, 3, 9, 'A', 5],
["Test", "A", "B01", 871963, 3, 9, 'G', 6],
["Test", "A", "B01", 1932523, 1, 10, 'T', 4],
["Test", "A", "B01", 1932523, 1, 10, 'A', 5],
["Test", "A", "B01", 1932523, 1, 10, 'X', 6],
["Test", "A", "B01", 667214, 1, 14, 'T', 4],
["Test", "A", "B01", 667214, 1, 14, 'G', 5],
["Test", "A", "B01", 667214, 1, 14, 'G', 6]]
for i in r:
print i[3]
test = Test()
test.type = i[0],
test.name = i[1],
test.sub_name = i[2],
test.pos = i[3],
test.s_type = i[4],
test._id = i[5],
test.chr.append(
letter=i[6],
no=i[7]
)
test.store(db)
如何修复 TypeError?