Max size of Python source code and compiled equivalent
Peter Otten
__peter__ at web.de
Thu Jul 21 14:17:49 EDT 2016
Malcolm Greene wrote:
> We're writing a DSL parser that generates Python code. While the size of
> our generated code will be small (< 32K), I wanted to re-assure the rest
> of our team that there are no reasonable code size boundaries that we
> need to be concerned about. I've searched for Python documentation that
> covers max Python source (*.py) and compiled file (*.pyc) sizes without
> success. Any tips on where to look for this information?
>
> Background: Python 3.5.1 on Linux.
I don't know if/where this is documented, but there are structural limits:
>>> def nested(N):
... return "".join(" " * i + "if 1:\n" for i in range(N)) + " " * N +
"print('hi')"
...
>>> print(nested(3))
if 1:
if 1:
if 1:
print('hi')
>>> exec(nested(99))
hi
>>> exec(nested(100))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 101
print('hi')
^
IndentationError: too many levels of indentation
More information about the Python-list
mailing list