I have a string \"{\'datetime\': datetime.datetime(2010, 11, 21, 0, 56, 58)}\" and I want to convert this to the object it represents. Using ast.literal_
\"{\'datetime\': datetime.datetime(2010, 11, 21, 0, 56, 58)}\"
ast.literal_
I ran into this issue and solved it by replacing the datetime object with a string like this:
if mystrobj.__contains__('datetime.datetime('): mystrobj = re.sub(r"datetime.datetime([(),0-9 ]*),", r"'\1',", mystrobj)