[Tutor] Don't understand this class/constructor call syntax

Alan Gauld alan.gauld at btinternet.com
Mon Jul 25 09:08:54 CEST 2011


dave wrote:
> Is it even possible to replace the implicit self argument of the initializer
> by passing something else?  If so, what would be the syntax.

Im not sure  this is what you mean but...

When you call a method on an object like:

class MyClass:
    def aMethod(self,spam): pass

anObject= MyClass()
anObject.aMethod(42)

You could replace the last line with:

MyClass.aMethod(anObject, 42)

This explicitly specifies the value of self in aMethod()

So you could in theory pass any object into the method,
although in most cases it would result in an error.


Is that what you mean?

Alan G.



More information about the Tutor mailing list