+3 votes
in Programming Languages by (56.8k points)

I am running a Python code on Windows machine wherein I have mentioned the path to a directory like this:

ofile = 'C:\cygwin64\home\myuser\Research\temp' + '\' +  ifile

But I am getting the following error. How can I fix the error?

File "zipafile.py", line 8
    ofile = 'C:\cygwin64\home\myuser\Research\temp' + '\' +  ifile
                                                                                                       ^
SyntaxError: EOL while scanning string literal

1 Answer

+2 votes
by (71.8k points)
selected by
 
Best answer

You need to use '\\' instead of '\' in the variable ofile. '\' is used for escape character and hence it's giving error.

ofile = 'C:\\cygwin64\\home\\myuser\\Research\\temp' + '\\' +  ifile


...