MemoryError in data conversion

Mok-Kong Shen mok-kong.shen at t-online.de
Mon Apr 14 17:20:33 EDT 2014


Am 14.04.2014 15:59, schrieb Peter Otten:

> You could use json, but you may run into the same problem with that, too
> (only later):
>
>>>> import json
>>>> items = []
>>>> for i in range(1000):
> ...     s = json.dumps(items)
> ...     items = [items]
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 2, in <module>
>    File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps
>      return _default_encoder.encode(obj)
>    File "/usr/lib/python3.3/json/encoder.py", line 191, in encode
>      chunks = self.iterencode(o, _one_shot=True)
>    File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode
>      return _iterencode(o, 0)
> RuntimeError: maximum recursion depth exceeded while encoding a JSON object
>>>> i
> 995
>
> The safest option is probably to serialize the original flist and slist, and
> use them to create the tree on the fly.

Thank you very much for your efforts to help me.

I have yet a question out of curiosity: Why is my 2nd list structure,
that apparently is too complex for handling by eval and json, seemingly
not a problem for pickle?

M. K. Shen




More information about the Python-list mailing list