From 5c455a3eafae7218ff1f3faa1eee6526325c35b2 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Sun, 26 Nov 2017 16:29:46 -0800 Subject: [PATCH] add IPython support for explore_odrive.py --- tools/explore_odrive.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/explore_odrive.py b/tools/explore_odrive.py index 10533a40..0991ee81 100755 --- a/tools/explore_odrive.py +++ b/tools/explore_odrive.py @@ -70,9 +70,20 @@ print('and "my_odrive.motor0.pos_setpoint = 10000"') print('will send motor0 to 10000') print('') -# Enter interactive python shell with tab complete enabled -import code -import rlcompleter -import readline -readline.parse_and_bind("tab: complete") -code.interact(local=locals(), banner='') +try: + # If this assignment works, we are already in interactive mode. + # so just drop out of script to existing shell + interpreter = sys.ps1 +except AttributeError: + # We are not in interactive mode, so let's fire one up + # Though let's be real, IPython is the way to go + print('If you want to have an improved interactive console with pretty colors,') + print('you can run this script in interactive mode with IPython with this command:') + print('ipython -i explore_odrive.py') + print('') + # Enter interactive python shell with tab complete enabled + import code + import rlcompleter + import readline + readline.parse_and_bind("tab: complete") + code.interact(local=locals(), banner='')