[Tutor] _curses.error: addstr() returned ERR

kromag@nsacom.net kromag@nsacom.net
Sat, 8 Dec 2001 13:11:54 -0600 (CST)


Howdy,

I have run on to a bit of a head scratcher with curses.

(The entire script with all the attendant postgres stuff can be found at 
http://www.angryrobot.org/Jabulon.py)


while 1:
        for room in roomlist:
            text='%s. '%(room)
            screen.addstr(text)
            prompt=screen.getstr()
            if prompt == 'read':
                pointer.execute("select * from post where room_name='%s'"%
(room))
                #pe is shorthand for "post element".
                for pe in pointer.fetchall():
                    msg_output=" Posted by %s, %s.n%snn"%(pe[2],time.ctime
(string.atof(pe[0])),pe[4])
                    screen.addstr(msg_output)
                    text='Press return to continuen'
                    screen.addstr(text)
                    screen.getch()
            elif prompt=='quit':
                sys.exit()
            elif prompt == '':
                pass
            elif prompt == 'enter':
                text="Enter Messagen> "
                screen.addstr(text)
                msg=screen.getstr()
                #testing only...
                rm='%s'%(room)
                dummy=time.time(),rm,username,msg
                pointer.execute("insert into post values(%s,'%s','%s','','%
s')"%(dummy))
                db.commit()
            else:
                pass


The first time I run through the loop 'reading' works just fine. However upon 
the second run it poops out with:

Traceback (most recent call last):
  File "./jabulon.py", line 90, in ?
    screen.addstr(msg_output)
_curses.error: addstr() returned ERR

The library reference states:

ERR 
Some curses routines that return an integer, such as getch(), return ERR upon 
failure. 

so I figure (brilliant, I know) that addstr() also returns ERR upon failure. 
Does the problem somehow lie in:

msg_output=" Posted by %s, %s.n%snn"%(pe[2],time.ctime(string.atof(pe
[0])),pe[4])

when I convert the date string to a float? Is there a safer way to do this?