Question

Im writing a Python curses program using vi editor. Would like to understand how to debug the module to debug it?

Is there any tools that I can use?

Was it helpful?

Solution

To easily debug a curses program, you can use curses.wrapper like this:

import curses
def make_me_an_error(screen, numerator, denominator):
    screen.addstr(0, 0, str(numerator/denominator)) # divide by zero

curses.wrapper(make_me_an_error, 1, 0)

Upon return or exception from make_me_an_error, wrapper automatically cleans up the screen and restores it to its original settings

From wrapper docs:

Initialize curses and call another callable object, func, which should be the rest of your curses-using application. If the application raises an exception, this function will restore the terminal to a sane state before re-raising the exception and generating a traceback. The callable object func is then passed the main window ‘stdscr’ as its first argument, followed by any other arguments passed to wrapper(). Before calling func, wrapper() turns on cbreak mode, turns off echo, enables the terminal keypad, and initializes colors if the terminal has color support. On exit (whether normally or by exception) it restores cooked mode, turns on echo, and disables the terminal keypad.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top