In my situation, I had \r\n
in my single-quoted dictionary strings. I replaced all instances of \r
with \\r
and \n
with \\n
and it fixed my issue, properly returning escaped line breaks in the eval'ed dict.
ast.literal_eval(my_str.replace('\r','\\r').replace('\n','\\n'))
.....