Is there a debugger in Pythonista?
If so, how does one use it? More generally, where can I find documentation on Pythonista?
Thank you for replying. I could find no mention of a debugger in that documentation.
The debugger is mentioned in "What's New" from version 3.0... I don't think there is a dedicated page.
There are a few ways to debug. One, when a script raises an exception, the built in debugger will pop up an exception window. You can click the little down arrow to show more details, which include an interactive stack trace, and a locals variable viewer.
This built in debugger can also be accessed by setting break points in the editor -- longpress on a line to bring up the context menu, and there is an option to add a breakpoint. When you run the code, you can also long press the play button, which gives you the option to enter with the debugger (you might need to longpress play even when you set breakpoints, but I forget). With breakpoints, you can step in or out of functions, single step through the code, etc, and then view the locals.
The limitation of the built in debugger is that you cannot modify variables, or execute code except for stepping through existing code.
The other method is the standard
pdbmodule. After an exception occurs, in the console window you can use
import pdb pdb.pm()
To start the post mortem debugger. This does let you evaluate expressions, etc. The console is somewhat limited in that history and auto completion don't work.
You can also use pdb to set breakpoints in your code using
import pdb pdb.settrace()
Wherever you want a breakpoint. Then, the code will drop to console.
Note that the pdb method won't work for debugging UI code, unless you present using
panelon iPad. Fullscreen or sheet can only be debugged using the visual debugger. Panel does let you swap back and forth between console and the UI panel. Also, pdb won't work inside UI functions that run on the so called main thread -- such as button actions. Best to just add print statements, or
console.hud_alertfor that sort of thing.
Finally, for scene, none of the debugging methods above really work well, except for print, or better yet adding logging data as scene elements (like boxes, or text overlays on your objects).
By the way, I highly recommend reading very carefully the "using Pythonista" section of the docs. There are some good tips/tricks that aren't documented elsewhere. For instance, swiping on the extra key row makes it easy to nudge cursor around (you can also two finger scroll around on the keyboard)
Also, skim the "Pythonista Modules" which shows the custom modules for iOS, and the preinstalled modules (which you shouldn't try to reinstall, generally).
Also, read the what's new, there are some subtleties only documented there.
The generic python documentation is included with pythonista, but includes info that doesn't always work with the python included with Pythonista. For instance,
subprocessdoesn't work on iOS.
Thank you very much for your extensive reply, it is very much appreciated and helpful. I was able to set a breakpoint, but using the debugger and stepping through the code seems quite difficult. I will keep trying