shared-python-startup/pythonstart
Tomáš Chvátal 6ce35be87f Accepting request 820864 from home:alarrosa:branches:devel:languages:python:Factory
- Import readline in the save_history handler. Otherwise the call
  to readline.write_history_file doesn't work (the readline import
  at the beginning of the file is already removed) and is silently
  ignored by the exception catcher.

OBS-URL: https://build.opensuse.org/request/show/820864
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:Factory/shared-python-startup?expand=0&rev=11
2020-07-14 12:39:50 +00:00

41 lines
871 B
Python

# startup script for python to enable saving of interpreter history and
# enabling name completion
# import needed modules
import atexit
import os
import readline
import rlcompleter
import sys
# where is history saved
ver = "%d.%d" % sys.version_info[:2]
historyPath = os.path.expanduser("~/.pyhistory%s" % ver)
# handler for saving history
def save_history(historyPath=historyPath):
import readline
try:
readline.write_history_file(historyPath)
except:
pass
del readline
# read history, if it exists
if os.path.exists(historyPath):
readline.set_history_length(10000)
readline.read_history_file(historyPath)
# register saving handler
atexit.register(save_history)
# enable completion
readline.parse_and_bind('tab: complete')
# cleanup
del os, atexit, readline, rlcompleter, save_history, historyPath
# vim:set ft=python: