primes=loadtxr() cmd not working
Title
Question
I am using Python in windows10. Used !type for loading file. But unable to perform loadtxt() cmd;to store the list in variable primes.
File "<ipython-input-4-fb9b7fac2a2b>", line 1
primes=loadtxt("C:\Users\Kriti\OneDrive\Desktop\Primes.txt")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Python-3.4.3 Loading-Data-From-Files 02-03 min 0-10 sec
Answers:
<a href="https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca" target="" title="">https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca</a>
The error message you're seeing indicates that Python encountered a string with a Unicode escape sequence that is truncated, meaning it doesn't have the required number of hexadecimal digits. The position 2-3 in the error message refers to the location in the string where the error occurred.
You can solve this error "<a href="http://net-informations.com/python/err/codec.htm" target="" title="">codec can't decode bytes</a>" by using a raw string by prefixing your string with the letter "r". Raw strings don't interpret backslashes as escape characters.
path = r"C:\Users\User\Documents\file.txt"
Double the backslashes in your string
path = "C:\\Users\\User\\Documents\\file.txt"
Use forward slashes instead of backslashes
path = "C:/Users/User/Documents/file.txt"
Login to add comment