I was reading through this question and began to wonder why the _
character only represents the result of the last executed statement in interactive modes, and not through actual script execution.
Script execution mode:
$ python3 -c '1;print(_)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name '_' is not defined
Interactive mode:
Tue Dec 18 09:41:20 CST 2018 | /Users/user
$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
1
>>> print(_)
1
What is the reasoning for this "feature" only being available in interpretive modes?