Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 0 years ago

Max Alekseyev gravatar image

The error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

can be seen even at Sagecell, where the file itself is missing. However, the error is not about the file content but about its name, which contains escape characters (backslashes). Each of them must either doubled, or the whole string must be declared as raw:

f=open(r"C:\Users\karen\Desktop\factcipher.txt", "w", encoding="utf8")

Note the r in front of the opening quotation mark.

click to hide/show revision 2
No.2 Revision

The error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

can be seen even at Sagecell, where the file itself is missing. However, the error is not about the file content but about its name, which contains escape characters (backslashes). Each Either each of them must either be doubled, or the whole string must be declared as raw:

f=open(r"C:\Users\karen\Desktop\factcipher.txt", "w", encoding="utf8")

Note the r in front of the opening quotation mark.

click to hide/show revision 3
No.3 Revision

The error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

can be seen even at Sagecell, where the file itself is missing. However, the error is not about the file content but about its name, which contains escape characters (backslashes). Either each of them must be doubled, or the whole string must be declared as raw:

f=open(r"C:\Users\karen\Desktop\factcipher.txt", "w", "r", encoding="utf8")

Note the r in front of the opening quotation mark.