How to parse a big file using ast.literal_eval without causing MemoryError? For example, the file I want to parse is 41MB.
I watched the process, and found that python took more than 3G memory. I'm using a 32-bit system, so it's up to the process's max memory.
Why does ast.literal_eval take so much memory as it only parses to get the data structure? Is there any way to reduce the memory usage?
By the way, the code is:
import ast
file = open(file_name, 'r')
data = ast.literal_eval(file.read())
file.close()
the exception is
File "/usr/local/lib/python2.7/ast.py", line 49, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "/usr/local/lib/python2.7/ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
MemoryError
Thanks!