超級網迷

超級網迷+ 電腦迷+ 音樂迷
個人資料
正文

How to fix the issue with last command repeat in python interpre

(2014-07-10 13:15:24) 下一個

The built-in version with RedHat 6.2 is python 2.6.6. On top of the OS, I installed python 2.7.3. However, the newly installed version has an issue: The python interpreter shell does not support recall of the last command. The following are the steps to fix it:

1) In your ~/.bashrc, add variable "PYTHONSTARTUP":
export PYTHONSTARTUP=$HOME/.pythonstartup

2) Put your python code in $HOME/.pythonstartup, like:
import rlcompleter
import readline

readline.parse_and_bind("tab: complete")

3) Please read python man page for more infomation:
$ man python

Note: you may need to install python module (such as readline-6.2.4.1) or
ncurses-devel-5 from (RPM) Package Manager GUI.

====== More detailed approch ==============
http://stackoverflow.com/questions/4289937/-
-how-to-repeat-last-command-in-python-interpreter-shell
===================================

1) PYTHONSTARTUP environment variable is set in file .pythonstartup:

# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter

2) You will need to have the modules readline, rlcompleter to enable this.
Check out the info on this at : http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP.
or
How to configure and use python interpreter

3) Modules required:
    http://docs.python.org/library/readline.html
    http://docs.python.org/library/rlcompleter.html

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.