Hi Gerald,

When you define an instance method, the first parameter (in the definition) represents the instance. By convention, you would name it "self":

#####################
class B:
   def foo(self, x):
      print "we have two parameters: " + str(self) + " and " + x
#####################

then calling

######################
b = B()
b.foo("x")
######################

would be equivalent to

######################
b = B()
B.foo(b, "x")
######################


So, as you have noted, you need at least one parameter to attach the method to an instance. This is because the instance _is_ the parameter. Python does this for you internally.


For more documentation you should read the paragraph about classes in the tutorial.

Regards,
Matthias
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to