what happens when the file begin read is too big for all linestobe?read with "readlines()"

Fredrik Lundh fredrik at pythonware.com
Sun Nov 20 11:45:07 EST 2005


Ross Reyes wrote:

> Maybe I'm missing the obvious, but it does not seem to say what happens when
> the input for readlines is too big.  Or does it?

readlines handles memory overflow in exactly the same way as any
other operation: by raising a MemoryError exception:

 http://www.python.org/doc/current/lib/module-exceptions.html#l2h-296

> How does one tell exactly what the limitation is to the size of the
> returned list of strings?

you can't.  it depends on how much memory you have, what your
files look like (shorter lines means more string objects means more
overhead), and how your operating system handles large processes.
as soon as the operating system says that it cannot allocate more
memory to the Python process, Python will abort the operation and
raise an exception.  if the operating system doesn't complain, neither
will Python.

</F>






More information about the Python-list mailing list