简体   繁体   English

Python函数返回None

[英]Python function returns None

I have the following piece of code: 我有以下代码:

def retornaReplicas(verify_key):
    connection = sqlite3.connect('servidor.db')
    cursor = connection.cursor()

    sql = 'SELECT replicas FROM arquivos_sad WHERE verify_key="%s"' % (verify_key)
    cursor.execute(sql)
    resultado = cursor.fetchone()

    return '@'.join(resultado)

I am debugging this code on Python interactive terminal and if I do: 我在Python交互式终端上调试此代码,如果我这样做:

print retornaReplicas(verify_key)

It returns 'None'. 它返回'None'。 But if I type the commands manually (instead of a function) like this: 但是,如果我手动键入命令(而不是函数),如下所示:

connection = sqlite3.connect('servidor.db')
cursor = connection.cursor()

sql = 'SELECT replicas FROM arquivos_sad WHERE verify_key="%s"' % (verify_key)
cursor.execute(sql)
resultado = cursor.fetchone()
print '@'.join(resultado)

it works. 有用。 Python doesn't give any errors too. Python也没有给出任何错误。 Why this return instatement isn't working? 为什么这种恢复运行不起作用?

BTW, verify_key is a UUID that I set up manually for debugging purposes (and it's a known value) and this code is using sqlite3 databases to make a consult. BTW,verify_key是我手动设置用于调试目的的UUID(并且它是已知值),并且此代码使用sqlite3数据库进行咨询。

Sorry, now it worked. 对不起,现在有用了。 I think that something that I imported before made some strange bug or something. 我认为我之前导入的东西会产生一些奇怪的错误。 After exiting the old shell and opening another one it worked. 退出旧壳并打开另一个后,它工作了。

Btw, I just don't post the whole code because it's a bloody mess. 顺便说一句,我只是不发布整个代码,因为它是一个血腥的混乱。 I really don't like it, but this is not originally my code and I don't really have the time to rewrite it (this is my project to graduate on Computer Science). 我真的不喜欢它,但这不是我原来的代码而且我没有时间重写它(这是我的计算机科学专业毕业的项目)。

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

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