Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: syntax error near unexpected token `(' - Python

Tags:

python

syntax

# from lxml import etree;  import module2dbk;  print module2dbk.xsl_transform(etree.parse('test-ccap/col10614/index.cnxml'), []);  Error: bash: syntax error near unexpected token `(' 
like image 453
Jessica Burnett Avatar asked May 20 '12 18:05

Jessica Burnett


People also ask

How do you fix unexpected tokens in Python?

The error message indicates that the script gets executed by bash, not python. Try adding #!/usr/bin/python as the first line of the file.

What does bash syntax error near unexpected token `(' mean?

bash: syntax error near unexpected token. It means you are typing a mongo shell command into bash shell. You must connect to your cluster with the mongo command first. system (system) closed September 14, 2022, 12:52am #3.

What Is syntax error near unexpected token?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.

What is unexpected token in Python?

Unexpected TokenThis is simply down to a syntax error (your fault, I'm afraid). Perhaps you forgot the ':' after a conditional branch or there is an unclosed parenthesis left somewhere in your code? Python scripts are broken down into 'tokens' which helps the program navigate the logic of your code.


2 Answers

add #!/usr/bin/env python at the top of your script, or call your script using python myscript.py

like image 200
zmo Avatar answered Sep 19 '22 11:09

zmo


Are you typing this at the unix command prompt? You should be doing this inside the python environment, ie. type python at the prompt and work from there.

Also, no ; needed at the end of the line in Python

like image 20
Levon Avatar answered Sep 19 '22 11:09

Levon