Is it possible in Python to decorate a function so that its begin and end are logged?
<p>For logging, I would like each function to log its own name at the start and end of the function.</p>

<pre><code>def my_function():
    print("Enter my_function")
    # ...
    print("Leave my_function")
</code></pre>

<p>If I change the name of the function, I have to update these print messages as well. I am looking for a way to automate this.</p>

<pre><code>def my_decorator(func):
    print("Enter ", func.__name__)
    func()
    print("Leave ", func.__name__)

def my_function():
    # do the work
    pass

# main:
my_decorator(my_function)
</code></pre>

<p>Is this possible in a simple way, maybe using decorators? How would this look like if my_function had parameters?</p>