calling class methods as functions

Bengt Richter bokr at oz.net
Tue Apr 9 05:07:13 EDT 2002


On Tue, 09 Apr 2002 10:03:04 +0200, Giorgi Lekishvili <gleki at gol.ge> wrote:

>Hello!
>
>I wonder if someone explaines tom how can I overcome the following
>problem in Python2.0 (I have to use this interpreter):
>suppose, we have 2 classes, B, and C.
>
>in class B we have a method "write"
>
>in class C we have a method "write"
>
>def write (self, arg):
>    import B
>    res=B.B.write(self, arg)    #res is a string being either "ok" or
>"failure"
>    del B
>    return res
>
>
>The interpreter gives an error, that class isntance must be given as 1st
>argument.
>
>What's wrong?
>
>Thanx,
>Giorgi
>
>PS. I know that the best solution is to make a baseclass and put the
>method "write" there. Of course. But I would like to know why this
>solution fails.
>
I can't tell what you mean by "this solution" unless you post actual code.
Just make a minimal example and show how it fails by copying a session
directly with copy/paste. Showing the call that gives the error.

Regards,
Bengt Richter



More information about the Python-list mailing list