How to debug python + curses? [was: RE: Applying winpdb_reborn]

Alan Gauld alan.gauld at yahoo.co.uk
Sun May 30 16:37:53 EDT 2021


On 30/05/2021 18:26, pjfarley3 at earthlink.net wrote:
> I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3
> at that time), but could not figure out how to use it to debug a python
> script that uses the curses module.

You are not alone. debugging curses is one of the biggest obstacles to
its use.

My approach is to define a status line at the bottom of my program and
write print statements into that window. Something like:

def main(stdwin):
    appwin = curses.newwin(...) # LINES-1 high
    status = curses.newwin(...) # 1 line high positioned on bottom
    # more code here
    status.addstr(0,0, "Value of foo = %s" % foo)

curses.wrapper(main)

After debugging the status window can either be retained as an
application status bar or removed and the main window
enlarged by one line...

If anyone else has found a better way to debug curses code I'm
also keen to hear!

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Python-list mailing list