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

 Solution -

CASE1- If you are working with file path location for example-

xlrd.open_workbook('C:\Users\xyz\Python_Local\File1.xls')

Then it will throw the "Unicode"  error as  \U represents the Unicode escape because this is normal string not raw string.

So use raw string to avoid this error by following methods-

(r'C:\Users\xyz\Python_Local\File1.xls')

('C:\\Users\\xyz\\Python_Local\\File1.xls')

('C:/Users/xyz/Python_Local/File1.xls')

CASE2- If we use normal string to print for example-

print('Hello World") then it is fine

If we want special character as normal character for example-

print('It's world') # will throw error 

so we have use '\'  escape  character to make ' normal character.

print('It\'s world')


Comments

Popular posts from this blog

Read the excel and insert data into My SQL using Python