【问题标题】:Invalid syntax showing up in pylint [closed]pylint中显示无效语法[关闭]
【发布时间】:2026-01-06 18:20:02
【问题描述】:

此 python 代码显示此无效语法(第 16 行) pylint(syntax-error)[15,10] 此处错误显示在分号(:)

for record in colleges:
    obj.writerow([record['collegeId'], record['collegeName'], record['courseType'], record['city'], record['fees'], record['pinCode']])

【问题讨论】:

  • 请向我们提供一个可重现的最小示例,以便我们为您提供帮助。
  • for 循环的语法错误。在末尾添加分号。
  • 上一行中可能出现括号不平衡等错误。
  • 所以问题现在解决了,你应该接受答案。为什么你实际上编辑了这个问题?现在没有意义了……
  • 感谢@Matthias 问题解决了

标签: python visual-studio-code syntax-error pylint opencsv


【解决方案1】:

假设 obj 是 csv.Writer。即便如此,你似乎只是少了一个冒号?

for record in colleges:
    obj.writerow([
        record['collegeId'],
        record['collegeName'],
        record['courseType'],
        record['city'],
        record['fees'],
        record['pinCode']
    ])

【讨论】:

  • 是的,这里 obj 是 csv.writer 但添加冒号后仍然显示相同的错误
  • @sowmyapanjala,这是运行时语法错误还是只是来自 pylint 的消息?