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...

1
  • 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__ Commented May 11, 2016 at 21:45

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I discovered the whole print became a function thing, but didn't get my parenthesis right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.