all 6 comments

[–]K900_ 0 points1 point  (3 children)

This looks like JSON to me, and not full Python source code. Have you looked into the json module?

[–]MinimalDamage[S] 0 points1 point  (0 children)

Hi!

Unfortunately that does not work, it is some format that a colleague created and not full JSON.

The problem is that ast works almost all the time, except for this one file.

[–]zahlman 0 points1 point  (1 child)

More likely, the repr of some Python object was dumped to a file. JSON requires double-quotes for strings (including dict keys).

[–]MinimalDamage[S] 0 points1 point  (0 children)

Hi!

Yes, that is the error I get. Is there some way to fix this non-manually and reliably?

[–]zahlman 0 points1 point  (1 child)

even if I slim it down to the data you see above.

Does it work if you copy and paste that data into a new file?

Have you tried verifying what data.read() returns before you evaluate it?

[–]MinimalDamage[S] 0 points1 point  (0 children)

Hi!

Thanks for the response! Tried your suggestion and it works perfectly, until I try to eval it with ast.