From 1674bfd2560de067b11ce390b3dd7299f782feb3 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Thu, 16 Feb 2012 13:32:55 -0500 Subject: [PATCH] * Added workaround so at least interactive python detection works (although not perfectly) in python <= 2.5. --- interactive_tools.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/interactive_tools.py b/interactive_tools.py index 4fbddd7..ed3b291 100644 --- a/interactive_tools.py +++ b/interactive_tools.py @@ -64,15 +64,23 @@ def detect_interactive(global_ns=None): * For ipython, see if "__IPYTHON__" is defined in the user's global namespace. * For "python -i" invocation, sys.flags.interactive will be set to True. + (python 2.6+ only) * For vanilla "python" invocation with no argument, then sys.ps1 variable exists. """ + def is_python_i(): + # This approach only works for Python 2.6+ + try: + return sys.flags.interactive + except: + return False + (g, b) = get_global_namespace_(global_ns) if "__IPYTHON__" in g or hasattr(b, "__IPYTHON__"): return { 'session': 'ipython', } - elif sys.flags.interactive: + elif is_python_i(): # sys.flags.interactive: return { 'session': 'python -i', }