calling a class instance of function

"Nils Oliver Kröger" NO_Kroeger at gmx.de
Thu Dec 21 05:28:10 EST 2006


Hi,

Methods i.e functions bound to a class instance (or object) the self argument in their definition:

[code]
class pid:
    def add(self, toadd):
        pass #or some sensible code
[/code]

If you want to define a method without that implicit self argument you'll have to make this method a static:

[code]
class pid:
    @staticmethod
    def staticadd (param1, param2):
        pass #or some sensible code
[/code]

Furthermore, your test() seems to be rather a function than a class:
You want to use this function to test the pid class but what you do with your code below is to define a class test which inherits pid. I'm not really sure what the following lines do ... this would usually be the place to introduce class variables.

Hope that Helps!

Greetings

Nils

-------- Original-Nachricht --------
Datum: 21 Dec 2006 11:09:32 +1100
Von: Pyenos <pyenos at pyenos.org>
An: python-list at python.org
Betreff: calling a class instance of function

> 
> class pid:
>     "pid"
>     def add(original_pid,toadd):
>         "add pid"
>         original_pid.append(toadd)
>         return original_pid
>     def remove(something_to_remove_from,what):
>         "remove pid"
>         something_to_remove_from.remove(what)
>         return something_to_remove_from
>     def modify(source,element,changewiththis):
>         "modify pid"
>         source[source.index(element)]=changewiththis
>         return source
> 
> class test(pid):
>     pid.original=[1,2,3]
>     pid.toadd=4
>     pid.add(pid.original,pid.toadd) # error here says that
>                                     # it expects pid instance as first arg
>                                     # not a list that it got.
> 
> why do i get an error?
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer



More information about the Python-list mailing list