forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractivePythonTest.py
executable file
·42 lines (30 loc) · 1.24 KB
/
interactivePythonTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import sys
import os
import readline
import atexit
import ctypes
def interactive_inspect_mode():
# http://stackoverflow.com/questions/640389/tell-whether-python-is-in-i-mode
flagPtr = ctypes.cast(ctypes.pythonapi.Py_InteractiveFlag,
ctypes.POINTER(ctypes.c_int))
return flagPtr.contents.value > 0 or bool(os.environ.get("PYTHONINSPECT",False))
if __name__ == '__main__':
#############################################
## Load and save command line history when ##
## running interactively. ##
#############################################
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
atexit.register(save_history)
readline.parse_and_bind("set show-all-if-ambiguous on")
readline.parse_and_bind("tab: complete")
if os.path.exists (historyPath) :
readline.read_history_file(historyPath)
readline.set_history_length(-1)
if not interactive_inspect_mode():
print("python -i `which interactivePythonTest.py` ")