簡體   English   中英

TypeError:int()參數必須是字符串或數字,而不是使用ouchdb-python的“元組”

[英]TypeError: int() argument must be a string or a number, not 'tuple' with couchdb-python

我有

$ 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?

您需要刪除代碼中的逗號,這樣就不會有錯誤。

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM