What's the difference between running a script under command box and interpreter?

Chris Angelico rosuav at gmail.com
Sun Nov 3 21:19:19 EST 2019


On Mon, Nov 4, 2019 at 1:01 PM <jfong at ms4.hinet.net> wrote:
>
> Chris Angelico於 2019年11月4日星期一 UTC+8上午8時43分07秒寫道:
> > Ah, that's a fair point. If you specifically WANT that behaviour, what
> > you can do is invoke the script interactively:
> >
> > python3 -i test.py
> >
> > That'll run the script as normal, and then drop you into the REPL. All
> > your interactive globals *are* that module's globals.
> >
> > ChrisA
>
> It surprises me that REPL has essential different behavior in these two situations.
>

Not really. In each case, the REPL lets you interactively execute code
as part of a module. If you start with "-i somescript.py", it starts
out by running the contents of that script; otherwise, you start with
nothing (as if you ran "-i empty-file.py"). The REPL does the same
thing every time; it's a difference between creating the functions
directly and importing them.

ChrisA


More information about the Python-list mailing list