Hlavní navigace

Pythoní interpreter - Interaktivní režim

14. 9. 2008 23:11 (aktualizováno) Tomáš Ehrlich

Během pročítání Pythoního manuálu jsem narazil na modul readline, následně na rlcompleter a odtud už byl jen kousek k hledání, jak nastavit tab-completion při spuštění interpreta v interaktivním režimu. Jako bonus jsem našel automatické ukládání historie příkazů.

Skript .pythonrc.py

import atexit, os, readline, 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)

readline.parse_and_bind ('tab:complete')

atexit.register(save_history)

del os, atexit, readline, rlcompleter, save_history, historyPath

Nastavení proměnné PYTHONSTARTUP

export PYTHONSTARTUP=/home/elvard/.pythonrc.py

Nelze použít ~ místo $HOME, v manuálu řečeno…

Sdílet