Pycharm无法识别打印选项args

时间:2016-06-29 02:23:13

标签: python printing pycharm

我正在使用PyCharm CE 2016.2和python interpreter 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

有没有人有任何线索?百万谢谢!

1 个答案:

答案 0 :(得分:0)

当您拨打Python 2时,

subprocess.call(['python', 'test.py'])即被启动。

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

相关问题