REPL with multiple function definitions
Chris Angelico
rosuav at gmail.com
Sun Jun 26 18:37:00 EDT 2022
On Mon, 27 Jun 2022 at 08:15, Rob Cliffe via Python-list
<python-list at python.org> wrote:
>
> This 2-line program
>
> def f(): pass
> def g(): pass
>
> runs silently (no Exception). But:
>
> 23:07:02 c:\>python
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def f(): pass
> ... def g(): pass
> File "<stdin>", line 2
> def g(): pass
> ^
> SyntaxError: invalid syntax
> >>>
>
> Is there a good reason for this?
The REPL compiles one statement at a time. A file is allowed to
contain multiple statements.
ChrisA
More information about the Python-list
mailing list