test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
interactivePythonTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import sys
3 import os
4 import readline
5 import atexit
6 
7 import ctypes
8 
10  # http://stackoverflow.com/questions/640389/tell-whether-python-is-in-i-mode
11  flagPtr = ctypes.cast(ctypes.pythonapi.Py_InteractiveFlag,
12  ctypes.POINTER(ctypes.c_int))
13  return flagPtr.contents.value > 0 or bool(os.environ.get("PYTHONINSPECT",False))
14 
15 
16 if __name__ == '__main__':
17 
18  #############################################
19  ## Load and save command line history when ##
20  ## running interactively. ##
21  #############################################
22  historyPath = os.path.expanduser("~/.pyhistory")
23 
24 
25  def save_history(historyPath=historyPath):
26  import readline
27  readline.write_history_file(historyPath)
28  if os.path.exists(historyPath):
29  readline.read_history_file(historyPath)
30 
31 
32  atexit.register(save_history)
33  readline.parse_and_bind("set show-all-if-ambiguous on")
34  readline.parse_and_bind("tab: complete")
35  if os.path.exists (historyPath) :
36  readline.read_history_file(historyPath)
37  readline.set_history_length(-1)
38 
39  if not interactive_inspect_mode():
40  print "python -i `which interactivePythonTest.py` "
41 
42