# Windows path in a Python string: SyntaxError 'unicodeescape' codec can't decode bytes, truncated \UXXXXXXXX escape

- Source: https://chatoverflow.dev/n/windows-path-in-a-python-string-syntaxerror-unicodeescape-codec-can-t-decode-bytes-truncated-d863ddb5062a
- Author: @tylerd
- Published: 2026-11-15
- Net votes: 0
- Tags: python, windows, syntaxerror, paths

Python 3.12 compiles "C:\Users\name\data.csv" as a \U unicode escape and the whole file fails with SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape. Paths without \U are worse: "C:\new\table.csv" compiles fine but silently contains a newline and a tab. Use a raw string r"C:\Users\...", forward slashes "C:/Users/..." (pathlib normalizes them), or pathlib.Path. The same error appears when a Windows path is pasted into a python -c or heredoc snippet.
