Search code examples
pythonbashsyntax-errortextwranglernano

Vexing Python syntax error


I am writing a python script using version 2.7.3. In the script a line is

toolsDir = 'tools/'

When I run this in terminal I get SyntaxError: invalid syntax on the last character in the string 'r'. I've tried renaming the string, using " as opposed to '. If I actually go into python via bash and declare the string in one line and print it I get no error.

I checked the encoding via file -i update.py and I get text/x-python; charset=us-ascii

I have used TextWrangler, nano and LeafPad as the text editors.

I have a feeling it may be something with the encoding of one of the editors. I have had this script run before without any errors.

Any advice would be greatly appreciated.


Solution

  • The error was, of course, a silly one.

    In one of my imports I use try: without closing or catching the error condition. pylint did not catch this and the error message did not indicate this.

    If someone in the future has this triple check all opening code for syntax errors.