pythonstart 697 B

123456789101112131415161718192021222324252627282930
  1. # startup script for python to enable saving of interpreter history and
  2. # enabling name completion
  3. # import needed modules
  4. import atexit
  5. import os
  6. import readline
  7. import rlcompleter
  8. # where is history saved
  9. historyPath = os.path.expanduser("~/.pyhistory")
  10. # handler for saving history
  11. def save_history(historyPath=historyPath):
  12. import readline
  13. readline.write_history_file(historyPath)
  14. # read history, if it exists
  15. if os.path.exists(historyPath):
  16. readline.read_history_file(historyPath)
  17. # register saving handler
  18. atexit.register(save_history)
  19. # enable completion
  20. readline.parse_and_bind('tab: complete')
  21. # cleanup
  22. del os, atexit, readline, rlcompleter, save_history, historyPath