tag:blogger.com,1999:blog-2090254955591363148.post6205137459399273773..comments2022-04-01T14:28:21.992-07:00Comments on Imp of the perverse: Matlab's keyboard command in pythonVinayhttp://www.blogger.com/profile/01327082697686501006noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-2090254955591363148.post-55522864389231657542013-06-15T05:17:10.747-07:002013-06-15T05:17:10.747-07:00A bit late, but I've just come across this (fr...A bit late, but I've just come across this (from here http://nongeekrecipes.org/2013/02/16/is-there-a-python-equivalent-of-the-matlab-command-keyboard/):<br /><br />Is there a python equivalent of the matlab command keyboard?<br /><br />Sort of. Wherever you want to stop the execution of your code to have access to the python prompt (and to the current local variables) just insert the lines:<br /><br />import code<br />code.interact(local=locals())<br /><br />To resume the execution press Ctrl-D.<br />Darrennoreply@blogger.comtag:blogger.com,1999:blog-2090254955591363148.post-15764178274219370062012-12-19T16:38:05.824-08:002012-12-19T16:38:05.824-08:00When using this function, I found that multiple ca...When using this function, I found that multiple calls to keyboard() within a single execution of a script resulted in a ValueError thrown form the code.interact() function. While I didn't find the exact source of this error, I noticed that if I exited the python interaction with ctrl-d instead of quit(), the error went away.Anonymoushttps://www.blogger.com/profile/12416857172204347731noreply@blogger.comtag:blogger.com,1999:blog-2090254955591363148.post-79797924232882591942011-12-13T06:40:52.108-08:002011-12-13T06:40:52.108-08:00Or better still, use ipython, and call:
from IPyt...Or better still, use ipython, and call:<br /><br />from IPython.Debugger import Tracer; debug_here = Tracer()<br /><br />then you can just use<br /><br />debug_here()<br /><br />whenever you want to set a breakpointAnonymoushttps://www.blogger.com/profile/06494624139130321086noreply@blogger.comtag:blogger.com,1999:blog-2090254955591363148.post-74505279223428157302011-11-10T09:47:01.610-08:002011-11-10T09:47:01.610-08:00My world just became a happier place.My world just became a happier place.JohnSteillhttps://www.blogger.com/profile/16862896408987425539noreply@blogger.comtag:blogger.com,1999:blog-2090254955591363148.post-49164807450109125942011-08-12T20:11:06.031-07:002011-08-12T20:11:06.031-07:00I'm a long-time Matlab user, just converting t...I'm a long-time Matlab user, just converting to Python.<br /><br />This command is great!!!<br /><br />However, it only seems to work from a shell prompt (that is, if you run your program as<br /> > python prog.py )<br /><br />It seems to get stuck in an infinite loop when using the ipython interactive shell.<br /><br />Is there a way to make this work with ipython? <br /><br />Thanks!!!<br /><br />Luis.Anonymousnoreply@blogger.com