Change path='C:\Users\USER\Desktop\
to path='C:\\Users\\USER\\Desktop\\
In a Python string, the \
backslash character is used as an escape character to indicate that the next character is part of the string, even if otherwise illegal. For example, if your string needs to contain quotation marks, you would escape them.
print('He said, \'Good morning\'')
will print
He said, 'Good morning'
where not escaping the quotation marks would cause errors.
Your code includes a path
string with backslashes, path='C:\Users\USER\Desktop\'
, and Python believes you are intending to escape the U in Users and USER, and the D in Desktop, and the closing quote. (Escaping the other characters may cause you other problems later.) As the closing quote is now part of the string, the string hasn't actually been closed at all yet. It basically doesn't see the closing quote at all. Hence: "unterminated string literal".
You want your path string to include backslashes, but you do not want Python to interpret them as escape characters. The clever solution to that is to escape the backslash escape characters themselves, so Python interprets them as just backslash characters and not as escape characters. The first backslash of '\\'
functions as an escape character and tells Python to treat the next backslash as just a normal character.