如何修复“ str”对象无法调用

时间:2019-03-24 18:20:40

标签: python

我正在将我的应用程序连接到sql server,并希望将int类型的id转换为str类型,但会给出错误“无法调用'str'对象”

我已经在终端中尝试了该程序,程序成功运行,但是在运行主程序和res [0]的类型时出现错误,是

def findquestion(str):
    resp=""
    mydb=mysqlc.connect(host="localhost",user="admin",passwd="admin",database="admin")
    mycursor = mydb.cursor()
    mycursor.execute("select qid,title from questions where title like %s",("%"+str+"%",))
    results = mycursor.fetchall()
    mydb.close()
    for res in results:
        id=str(res[0])
        resp+="<a href='/question/"+id+"'>"+res[1]+"</a><br>"
    return resp

获取错误

  File "/opt/web-sites/app.py", line 150, in findquestion
    id=str(res[0])
TypeError: 'str' object is not callable

对不起,英语不好

2 个答案:

答案 0 :(得分:0)

错误是由于重新定义内置的let object = {}; let property = "a.b.c"; let value = 1; _.set(object, property, value); // sets property based on path let value = _.get(object, property, default); // gets property based on path 函数引起的。只需重命名您的参数,该错误即可自行解决。

答案 1 :(得分:0)

如注释中所指出,您的变量//setting the timeout for our wait to be 20 seconds (you can use whatever you want) WebDriverWait myWaitVar = new WebDriverWait(driver,20); try { WebElement myElement = myWaitVar.until(ExpectedConditions.elementToBeClickable(firstName))); //assert test failed! } catch(timeoutException timeout) { //whatever you want to do when the element is not clickable } 的范围存在问题

str