简体   繁体   English

TypeError:int()参数必须是字符串或数字,而不是使用ouchdb-python的“元组”

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

I got 我有

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

with the below script and couchdb-python (0.9): 使用以下脚本和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)

How is is possible to fix the TypeError? 如何修复TypeError?

You need to delete the comma in your code, then you'll have no error. 您需要删除代码中的逗号,这样就不会有错误。

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.

相关问题 TypeError:int()参数必须是字符串或数字,而不是&#39;tuple&#39; - TypeError: int() argument must be a string or a number, not 'tuple' 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组”。 在蟒蛇 - TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'. in python TypeError:float()参数必须是字符串或数字,而不是“ tuple” - TypeError: float() argument must be a string or a number, not 'tuple' django - int参数必须是字符串或数字,而不是&#39;元组&#39; - django - int argument must be a string or a number, not 'Tuple' 将元组转换为 integer Python,错误信息:TypeError: int() argument must be a string, a bytes-like object or a real number, - Convert a tupple into integer Python, error message: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'tuple' TypeError:int()参数必须是字符串或数字,而不是“ Popen” Python - TypeError: int() argument must be a string or a number, not 'Popen' Python Python:TypeError:int()参数必须是字符串或数字,而不是“ IPv4Network” - Python: TypeError: int() argument must be a string or a number, not 'IPv4Network' 类型错误:INT()参数必须是字符串或数字,而不是“字典” - TypeError: int() argument must be a string or a number, not 'dict' 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串或数字,而不是“元组” - TypeError: Error converting shape to a TensorShape: int() argument must be a string or a number, not 'tuple' TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM