Call a functor in Python
Question: Should be easy, but somehow I don't get it. I want to apply a given function.
Background is copy a class and applying a given method on the newly created
copy.

**Major Edit. Sorry for that.**

    
    
       import copy
       class A:
    
           def foo(self,funcName):
               print 'foo'
               funcName()
    
           def Bar(self):
               print 'Bar'
    
            def copyApply(self,funcName):
               cpy = copy.copy()
               # apply funcName to cpy??
    
        a = A()
        func = a.Bar()
        a.foo(func) # output 'Bar'
        b = a.copyApply(foo) # new copy with applied foo
    


Answer: Note that your `A.foo` does not take the _name_ of a function, but the
function itself.

    
    
    class A:
       def bar(self):
           print 'Bar'
    
       def apply(self, func):
           func()  # call it like any other function
    
       def copyApply(self, func):
           cpy = copy.copy(self)
           func(cpy)  # cpy becomes the self parameter
    
    a = A()
    func = a.bar  # don't call the function yet
    
    a.apply(func)       # call the bound method `a.bar`
    a.apply(a.bar)      # same as the line above
    a.copyApply(A.bar)  # call the unbound method `A.bar` on a new `A`
    

In python, `a.foo()` is the same as `A.foo(a)`, where `a` is of type `A`.
Therefore, your `copyApply` method takes the _unbound_ bar method as its
argument, whereas `foo` takes a _bound_ method.

