【问题标题】:mySql database has sqlite3.Cursor object at 0x104e18ea0 as output in tablemySql 数据库在 0x104e18ea0 处有 sqlite3.Cursor 对象作为表中的输出
【发布时间】:2017-05-08 01:36:15
【问题描述】:

我有一个名为 rank 的表

 id  Name 
 1    Roger
 2    Tom

另一个名为 PersonId 的表。在这里,我尝试在 personId 表中选择名称并添加 id。

def getRank(teamName):
    name = c.execute(ids = c.execute("SELECT id From rank where Name = '%s';" % Name)
    print "str val of rank: ",name.fetchall()[0][0],
    return str(name.fetchall()[0][0])

如果我输入“罗杰”,我期待

1

在我看到的公用线路界面中:

str val of rank:  1

但在数据库中它打印为

“sqlite3.Cursor 对象位于 0x104e18ea0”。

目前,PersonId 表的样子

id 

c.execute(插入 PersonId (id) 值 (?),[getRank('Roger')])

执行后,表格如下:

    id
sqlite3.Cursor object at 0x104e18ea0
sqlite3.Cursor object at 0x104e18ea0

我不确定为什么我得到的是对象位置的地址而不是实际值

任何想法或帮助将不胜感激

【问题讨论】:

  • 你的getRank() 函数没有返回任何东西,所以我希望数据库值是None
  • 我有,只是在复制粘贴时错过了那行,我已经编辑了问题。

标签: python mysql database sqlite


【解决方案1】:

发现问题。

只需要改变:

str(name.fetchall()[0][0])
       to
name.fetchall()[0][0]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    相关资源
    最近更新 更多