do_tables_exist()将返回False;如果存在需要创建的表,则返回字符串列表;该方法可以返回布尔值或列表,但不能同时返回两者。这是方法:
def create_tables(self):
""" Creates tables for RSS news feeds
Creates db tables where each RSS link feeds
into a separate table because it's easier
to aggregate then deaggregate.
"""
if self.do_tables_exist() != False:
# Open database locally
conn = sqlite3.connect(self.path + "FeedMe.db")
conn.isolation_level = None
c = conn.cursor()
transaction_query = "BEGIN; "
for table_name in self.do_tables_exist():
table = "CREATE TABLE " + table_name + \
"( primary_key text, title text," + \
" description text, link text, published text); "
transaction_query = transaction_query + table
# Which tables are being entered?
print "\t" + table_name
transaction_query = transaction_query + " COMMIT;"
# Create table in sqlite3
c.executescript(transaction_query)
# close sqlite3 db
conn.close()
elif self.do_tables_exist() == False:
print("\n\tNo new tables need to be created")
else:
raise UserWarning("do_tables_exist() not returning a value")
在接下来的一行中,我收到一个“TypeError:'bool'对象不可迭代”。
for table_name in self.do_tables_exist():
这让我感到困惑,因为我只想在do_tables_exist()返回列表时迭代对象。
你知道为什么我收到这个错误吗?感谢您的时间。
答案 0 :(得分:0)
尝试这样的事情
tables = self.do_tables_exist()
if tables:
for table_name in tables:
#do stuff