【问题标题】:Pycharm cannot recognize print option argsPycharm 无法识别打印选项 args
【发布时间】:2016-06-29 02:23:13
【问题描述】:

我正在使用 PyCharm CE 2016.2 和 python 解释器 3.5。当我尝试在控制台中输入以下内容时,该文件生成为“123”。

>>> with open('man_data.txt', 'w') as data:
        print('123', file=data)

但是,当我将相同的语句放入 test.py 文件并尝试使用 subprocess.call(['python', 'test.py']) 运行它时,它给出了

>>> subprocess.call(['python', 'test.py'])
    File "test.py", line 2
    print('123', file=data)
                     ^
SyntaxError: invalid syntax
1

有人有线索吗?百万谢谢!

【问题讨论】:

    标签: python printing pycharm


    【解决方案1】:

    Python 2 会在您调用subprocess.call(['python', 'test.py']) 时启动。

    尝试更改为subprocess.call(['python3', 'test.py']) 或按照here 的说明更新脚本。

    【讨论】:

    • 非常感谢!!在花了几个小时调试原因后,我终于解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 2013-03-06
    • 2014-05-21
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多