简体   繁体   English

Python sqlite3错误

[英]Python sqlite3 error

def menuAdiciona():
    nome = input("Digite o nome de quem fez o cafe: ")
    nota = int(input("Que nota recebeu: "))

    if len(str(nome).strip()) == 0:
        menuAdiciona()

    if (nota) == 0:
        menuAdiciona()

    if nota < 0:
        nota = 0

appears this: 出现此:

Can't convert 'int' object to str implicitly 无法将'int'对象隐式转换为str

First, the code you provided "works" in Python 2.7 and 3. 首先,您提供的代码在Python 2.7和3中“有效”。

A line number or stacktrace would be helpful, but assuming it's in the snippet you provided: 行号或堆栈跟踪会很有帮助,但是假设它在您提供的代码段中:

nota = int(input("Que nota recebeu: "))

Here nota is an int. 这里nota是一个int。

if len(str(nome).strip()) == 0:

The next line you're trying to cast it to a string without specifying how. 您尝试将其下一行强制转换为字符串而不指定方式。

Something like: 就像是:

if len(("%d" % nota).strip()) == 0:

should prevent the error. 应该防止错误。

That being said, the line still makes little sense. 话虽如此,这条线仍然没有意义。 You shouldn't have to strip() a string representation of an integer. 您不必strip()一个整数的字符串表示形式。

What are you trying to accomplish with strip() and the if len(...) == 0 parts? 您要使用strip()if len(...) == 0部分来完成什么工作?

Edit: Lastly, I think you want raw_input() instead of input() , unless you're shadowing that somewhere too. 编辑:最后,我认为您想要raw_input()而不是input() ,除非您也将其隐藏在某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM