使用 Python 3.5,我将多个多维列表插入到 MySQL 查询中,该查询将多行插入到表中。这是我的执行代码片段:
for x, y, z, i in zip(list1, list2, list3, list4):
cursor.execute(add_related_accounts_query.format(x[0], *y, *z, *i))
查询工作正常,但 PyCharm 给了我这个警告:
Duplicate *args
This inspection reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments and incorrect argument order.
如果我按 Alt+Enter 通过 PyCharm 修复警告,它会消除 *z, *i
,然后查询不再有效。
如果解决方案破坏了我的脚本,有人可以解释为什么会发出此警告吗?
最佳答案
PyCharm 可能只希望您将一个 *args 列表传递到函数中。你可以在扩展它们之前添加 x、y 和 i,我想 pycharm 会停止提示。
cursor.execute(add_related_accounts_query.format(x[0], *(y+z+i))
不过,您必须对 pycharm 警告持保留态度。它并不总是完美的。它有一组注释,您可以将其放在这样的行之前,以强制它忽略警告。
关于python - 为什么 PyCharm 会向我发出 "Duplicate *arg"的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33904751/