![]() |
syntax error? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: syntax error? (/thread-7508.html) |
syntax error? - Culm - Jan-13-2018 Newbie -- trying to learn python on mac. Installed v2 and v3. -- tried to run the following script from terminal: #!/usr/bin/python # -*- coding: latin-1 -*- import os, sys f = open(‘CROSSWD.TXT’, 'r+') for line in f: word=line.strip() if len(word)>20: print wordthis is the error message I get: (the symbol ^ appears under the first question mark -- this post has altered the position)No problem running it from the interpreter Thanks in advance RE: syntax error? - Gribouillis - Jan-13-2018 Your CROSSWD.TXT is surrounded with curly quotes, which are invalid string delimiters in the python syntax. This may happen if you copy and paste python code from certain files such as pdf files or rich text files to your python editor. Replace the curly quotes with normal quotes.
RE: syntax error? - wavic - Jan-13-2018 The name of the file must be surrounded in quotes. |