<p>I am trying to write a decorator to do logging:</p>

<pre><code>def logger(myFunc):
    def new(*args, **keyargs):
        print 'Entering %s.%s' % (myFunc.im_class.__name__, myFunc.__name__)
        return myFunc(*args, **keyargs)

    return new

class C(object):
    @logger
    def f():
        pass

C().f()
</code></pre>

<p>I would like this to print:</p>

<pre><code>Entering C.f
</code></pre>

<p>but instead I get this error message:</p>

<pre><code>AttributeError: 'function' object has no attribute 'im_class'
</code></pre>

<p>Presumably this is something to do with the scope of 'myFunc' inside 'logger', but I've no idea what.</p>

It seems that while the class is being created, Python creates regular function objects. They only get turned into unbound method objects afterwards. Knowing that, this is the only way I could find to do what you want:
```
```
def logger(myFunc):
    def new(*args, **keyargs):
        print 'Entering %s.%s' % (myFunc.im_class.__name__, myFunc.__name__)
        return myFunc(*args, **keyargs)

    return new

class C(object):
    def f(self):
        pass
C.f = logger(C.f)
C().f()
```
```
This outputs the desired result.
If you want to wrap all the methods in a class, then you probably want to create a wrapClass function, which you could then use like this:
```
```
C = wrapClass(C)
```
```