python在添加新行之前检查现有行时出错

python在添加新行之前检查现有行时出错,python,mysql,Python,Mysql,我编写了一些代码,用于检查表中现有的行,然后如果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) val

我编写了一些代码,用于检查表中现有的行,然后如果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)
可能是一个好主意,而不是在
int
(x.rowcount)
之间加一个空格,尽管这不会影响代码。检查以确保选项卡正确对齐,并且只有空格或选项卡,而不是两者都有。

检查是否没有任何选项卡与空格混合。如果有疑问,请删除空格并再次缩进。
numrows = int (x.rowcount)
                         ^
IndentationError: unindent does not match any outer indentation level