<p>当然可以,只要一个小的启动脚本。来自python教程中的<a href="http://docs.python.org/tutorial/interactive.html" rel="noreferrer">Interactive Input Editing and History Substitution</a>:</p>
<pre><code># Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
import atexit
import os
import readline
import rlcompleter
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
</code></pre>
<p>从Python 3.4开始,<a href="https://docs.python.org/3/whatsnew/3.4.html#other-improvements" rel="noreferrer">the interactive interpreter supports autocompletion and history out of the box</a>:</p>
<blockquote>
<p>Tab-completion is now enabled by default in the interactive interpreter on systems that support <code>readline</code>. History is also enabled by default, and is written to (and read from) the file <code>~/.python-history</code>.</p>
</blockquote>