我编写了一些代码来检查表中是否存在现有行,然后如果 id 不存在,则代码插入新行。这是代码
x.execute("SELECT id FROM headlines WHERE id="+ pid)
numrows = int (x.rowcount)
if numrows<1:
sql = '''insert into headlinesUS (id,feed_url,item_title,item_date,fetch_date)
values ("%s","%s","%s","%s","%s");'''
x.execute(sql, (pid,url,title,date,fetch))
connection.commit()
print("\n- " + title)
但是当我运行它时,我收到此错误:
numrows = int (x.rowcount)
^
IndentationError: unindent does not match any outer indentation level