0

Working on a CasperJS tutorial and I'm getting an error with my syntax. Using Python 3.5.1.

File: scrape.py

import os
import subprocess

APP_ROOT = os.path.dirname(os.path.realpath(__file__))
CASPER = '/projects/casperjs/bin/casperjs'
SCRIPT = os.path.join(APP_ROOT, 'test.js')

params = CASPER + ' ' + SCRIPT

print subprocess.check_output(params, shell=True)

Error:

File "scrape.py", line 10
    print subprocess.check_output(params, shell=True)
                   ^
SyntaxError: invalid syntax

YouTube Video tutorial: Learning to Scrape...

Casey
  • 536
  • 2
  • 14
  • 28
  • unrelated: 1- if `APP_ROOT` has spaces in it; the `check_output()` call may fail because `CASPER + ' ' + SCRIPT` is not how the command line should be created. It seems, you don't need the shell here 2- if you want to display the output; you don't need to capture it: `check_call([CASPER, SCRIPT])` 3- minor: you could [use `get_script_dir()` instead of `__file__`](http://stackoverflow.com/a/22881871/4279) – jfs May 11 '16 at 21:45

1 Answers1

1

print subprocess.check_output(params, shell=True) is Python 2 syntax. print is a keyword in Python 2 and a function in Python 3. For the latter, you need to write:

print(subprocess.check_output(params, shell=True))
jwodder
  • 54,758
  • 12
  • 108
  • 124
  • Thanks, I discovered the whole print became a function thing, but didn't get my parenthesis right. – Casey May 11 '16 at 18:48