Cannot call a s-lang method in an object
Bengt Richter
bokr at oz.net
Mon Oct 21 17:19:34 EDT 2002
On 18 Oct 2002 19:53:19 GMT, Marco Herrn <herrn at gmx.net> wrote:
>Hi there,
>
>first, sorry for the crossposting, but I don't know which newsgroup
>would be more appropriate.
>
>I am trying to write a program in python that uses s-lang for color
>output and keyboard handling (by using python-slang).
>
>Now, for the following code, everything runs fine:
>
>----------
>#! /usr/bin/env python
>
>from PySlang import *
>import sys
>
>def out():
> SLsmg_write_string("test")
>
>
>sl_init()
>out()
>SLsmg_refresh()
>sl_exit()
>----------
>
>But when putting the out() method in a class, it doesn't work:
>
>----------
>#! /usr/bin/env python
>
>from PySlang import *
>import sys
>
>class Test:
> def out():
> SLsmg_write_string("test")
>
>sl_init()
>test= Test()
>test.out()
>SLsmg_refresh()
>sl_exit()
>----------
>
>Then I see nothing and my screen is scrambled.
>Now I assume that there is an exception somewhere (I mean it is exactly
>when call the method test.out()). But I don't see the stacktrace. Surely
>this is because s-lang is hiding the output.
>
>But how can I see the stacktrace?
Unless what you are testing does something sneaky with stderr,
try something like this (running on old 1.5.2 Linux box, since you are on Linux?)
Python 1.5.2 (#1, May 28 2000, 18:04:10) [GCC egcs-2.91.66 19990314/Linux (egcs
- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> sys.stderr = open('myErrors.txt','a', 0)
>>> 1/0
(nothing shows on the screen)
Say that bombed your system, then get out and into a clean shell again:
>>>
bokr at springbok:~/junk$ cat myErrors.txt
Traceback (innermost last):
File "<stdin>", line 1, in ?
ZeroDivisionError: integer division or modulo
You can do the ~same on windows. You could even automate a look
at the error file with something like import os; os.system('start notepad myErrors.txt')
BTW, note the zero buffering parameter on the open, so things will get flushed
to the file immediately.
Regards,
Bengt Richter
More information about the Python-list
mailing list