0

I am new to python and trying to parse a string using split when i try to parse a log string i am getting the following error

  File "main.py", line 1
ans = "2021-08-19 19:13:32,516 :: INFO :: 10.104.220.55 :: config\ucs\manager.py:131 :: Fetching config from live device (can take several minutes)"
     ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 58-60: truncated \uXXXX escape

My code is simple:

ans = "2021-08-19 19:13:32,516 :: INFO :: 10.104.220.55 :: config\ucs\manager.py:131 :: Fetching config from live device (can take several minutes)"

test = ans.split("::")

print(test)

Thanks in advance

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Tony Frank
  • 248
  • 1
  • 2
  • 8
  • you need to use double ```\```. – ewokx Sep 15 '21 at 06:35
  • 1
    `\ ` is an escape character in python. `\u` starts a unicode escape sequence, but really you just wanted to write `\usc`. You can either make a raw string `r"2021-08-19..."` or double backslash to unescape the escape. `\\usc`. This has already been answered here on stackoverflow, so its a duplicate. – tdelaney Sep 15 '21 at 06:37

0 Answers0