ugly = "[{'ride': 1, 'pickup_time': datetime(2016, 3, 17, 15, 36, 35, 976202)},
{'ride': 2, 'pickup_time': datetime.datetime(2016, 3, 17, 15, 41, 35, 976202)}]"
# The actual variable contains a lot more dictionnaries...`
I'd like to convert the ugly variable as a real Python object.
I tried json.loads()
and ast.literal_eval()
but it's for one dict only.
That's why, before that, I tried to split this string into several dictionnaries, but the split()
method has only one delimiter, so it seems I could need a REGEX to do this.
What is the simplest way to do it? Thanks.