How do I declare a class member function in another class?

I have a class SubDevice with a function action .
For each instance of SubDevice I want to define another action, so it's a parameter of SubDevice's class constructor.
Now some of the action functions need additional parameters, but that's normally not a problem because I can write something like

sd1 = SubDevice(action=lambda: f1(param1, param2))

But how do I pass the instance of SubDevice as a parameter of the action function? I can't use self , because self refers to the class Device , where I instantiate SubDevice .

Now, I'm not sure where the variable parameter list would come into play. It seems to me that if you want a transparent interface, then you have to make the parameter list consistent. Can you give an example of what you had in mind?

Hi,
As Sharma said one solution would be to construct subclasses of SubDevice for every different action and I thought about doing that in the beginning. However, my instructor is against it. Of course he's more procedurally oriented than younger programmers, but I agree that it would be too much overhead to construct subclasses, as they would be too specialized and they don't need any additional parameters.

SuperDevice is larger device consisting of many different SubDevices. There could be numerous events when the plate_count has to decrease, so I have a separate method for it.
Now the problem is that I can't set the state field of SubDevice with action1 , as I don't know what to replace XXX with.

What exactly happens when a method is called? You may have noticed that x.f() was called without an argument above, even though the function definition for f specified an argument. What happened to the argument? Surely Python raises an exception when a function that requires an argument is called without any--even if the argument isn't actually used ...
Actually, you may have guessed the answer: the special thing about methods is that the object is passed as the first argument of the function. In our example, the call x.f() is exactly equivalent to MyClass.f(x). In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method's object before the first argument.

But making a function an attribute of an object doesn't automatically
make it a method:>>> class c:
... pass
...>>> o=c()
>>> o.x=f
>>> o.x()
wibble

There, f is a plain function that's an attribute.

To make a function into an instance's method, you need the
instancemethod() function of the new module:>>> def m(self):
... print "wibble"
...>>> import new
>>> o.m=new.instancemethod(m,o,c)
>>> o.m()
wibble

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...