我知道它已经在这里很多次了,但我没有找到适合我的案例的正确答案。
首先: 我正在制作一个简单的数据库系统(为我自己),它将在没有哈希等的情况下运行(至少现在是这样)。现在我卡住了。
import sys
import os
filename = ""
database = ""
path = ""
table = ""
class Nollty:
returns = 0
errors = 0
def __init__(self, filename, database):
self.filename = filename
self.database = database
self.path = self.filename + "databases/" + self.database
openfile = open(self.path + "/db_required", "r")
if not openfile.errors:
self.returns = 1
if not os.path.exists(self.path + "/db_required"):
self.returns = 0
openfile.close();
def select(self, table):
errors = 0
self.table = table
openfile = open(self.path + "/" + self.table, "r")
if not openfile.errors:
errors = 1
if not os.path.exists(self.path + "/" + self.table):
errors = 0
openfile.close();
nollty = Nollty("", "test")
if nollty.returns == 1:
print "Successfully connected to the database!"
query = nollty.select("aaa_auto")
if query.errors == 0:
print "Successfully chosen the table!"
错误输出是:
Traceback (most recent call last):
File "/home/spotrudloff/Python/Nollty/nollty.py", line 40, in <module>
if query.errors == 0:
AttributeError: 'NoneType' object has no attribute 'errors'
问题大概是我是PHP程序员,今天几个小时就学会了Python(所以我的想法还是“PHPy”)。
感谢所有的回应。
最佳答案
select()
不返回显式值,因此它具有 NoneType
返回值。更改您的代码,以便 select()
将返回 1 或 0,具体取决于您的代码是成功还是失败。
关于Python 的 AttributeError : 'NoneType' object has no attribute 'errors' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8859433/