Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:20

0001 #!/usr/bin/env python3
0002 import sys
0003 import os
0004 import readline
0005 import atexit
0006 
0007 import ctypes
0008 
0009 def interactive_inspect_mode():
0010     # http://stackoverflow.com/questions/640389/tell-whether-python-is-in-i-mode
0011     flagPtr = ctypes.cast(ctypes.pythonapi.Py_InteractiveFlag, 
0012                          ctypes.POINTER(ctypes.c_int))
0013     return flagPtr.contents.value > 0 or bool(os.environ.get("PYTHONINSPECT",False))
0014 
0015 
0016 if __name__ == '__main__':
0017 
0018     #############################################
0019     ## Load and save command line history when ##
0020     ## running interactively.                  ##
0021     #############################################
0022     historyPath = os.path.expanduser("~/.pyhistory")
0023 
0024 
0025     def save_history(historyPath=historyPath):
0026         import readline
0027         readline.write_history_file(historyPath)
0028         if os.path.exists(historyPath):
0029             readline.read_history_file(historyPath)
0030 
0031 
0032     atexit.register(save_history)
0033     readline.parse_and_bind("set show-all-if-ambiguous on")
0034     readline.parse_and_bind("tab: complete")
0035     if os.path.exists (historyPath) :
0036         readline.read_history_file(historyPath)
0037         readline.set_history_length(-1)
0038 
0039     if not interactive_inspect_mode():
0040         print("python -i `which interactivePythonTest.py` ")
0041 
0042