CMS 3D CMS Logo

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