[Tutor] Fixing a python curses bug in my program

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jul 7 07:09:14 EDT 2021


On 07/07/2021 11:54, Bithov Vinu Student wrote:

> version of the code; my problem is not the overall program but rather the
> init_curses() function, the prompt_review_card() function , and the quiz
> function, which are the only functions that use curses directly. When I run
> the program with the correct command line arguments (exemplar usage is
> shown in the comments and a test file is attached to this email)  it
> abruptly exits and my shell has its formatting changed so that every Enter
> results in it tabbing slightly away from me.

Ideally you should use the curses.wrapper() function.

But if you need to use some unusual initialization 9although it doesn't
look like you do!) wrap the curses stuff in a try/finally:


try:
   screen = init_curses()
   # your for loop here
finally:
   curses.endwin()


That should at least get you back to a sane screen.

As to what's causing it to crash, that's harder to tell
without an error trace. Hopefully the above will aid
you in getting there.


-- 
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 Tutor mailing list