Cannot call a s-lang method in an object

Steve Holden sholden at holdenweb.com
Mon Oct 21 10:01:56 EDT 2002


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?
> And why should it be a problem to call this method from a function?
>

The exception that is being raised is almost certainly because you are
defining a method with no arguments. Since the interpreter will always
provide the instance as the first argument to a method call, it will be
complaining about a one-argument call to a no-argument function. You should
try first of all redefining your method as shown below.

    class Test:
        def out(self):
            SLsmg_write_string("test")


However, as you have discovered it's more difficult to test in a framework
that doesn't allow you to see the standard error output. Perhaps you need to
consider running all this inside a try/except that will give you better
access to the error messages.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------
"






More information about the Python-list mailing list