0

I am using PyCharm CE 2016.2 and python interpreter 3.5. When I tried to type the following in console, the file is generated with '123'.

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

However, when I put the same statement into a test.py file and try to run it using subprocess.call(['python', 'test.py']), it gives

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

Does anyone has any clues? Million thanks!

1 Answers1

0

Python 2 is started when you call subprocess.call(['python', 'test.py']).

Try to change to subprocess.call(['python3', 'test.py']) or update the script as described here.

Community
  • 1
  • 1
user2235698
  • 7,053
  • 1
  • 19
  • 27