【问题标题】:Error when running a python script - invalid syntax运行 python 脚本时出错 - 语法无效
【发布时间】:2015-06-20 12:37:52
【问题描述】:

我在运行 python 脚本时不断收到此错误

sudo python net-creds.py
  File "net-creds.py", line 75
    ipr = Popen([‘/usr/local/bin/ip’, 'route'], stdout=PIPE, stderr=DN)
                 ^
SyntaxError: invalid syntax

【问题讨论】:

  • 你对输出做了什么?如果要存储输出,可以使用 check_output:c = check_output(["ip","route"])

标签: python django macos python-2.7


【解决方案1】:

你使用的是“`”而不是'。所以试试这个

ipr = Popen(['/usr/local/bin/ip', 'route'], stdout=PIPE, stderr=DN)

【讨论】:

  • 澄清:无效版本具有“智能引号”。有效版本具有普通的“哑引号”。
猜你喜欢
  • 1970-01-01
  • 2022-01-26
  • 1970-01-01
  • 1970-01-01
  • 2013-10-07
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
相关资源
最近更新 更多