title: dynamically adding functions to a Python module
body: <p>Our framework requires wrapping certain functions in some ugly boilerplate code:</p>
  
  <pre><code>def prefix_myname_suffix(obj):
      def actual():
          print 'hello world'
      obj.register(actual)
      return obj
  </code></pre>
  
  <p>I figured this might be simplified with a decorator:</p>
  
  <pre><code>@register
  def myname():
      print 'hello world'
  </code></pre>
  
  <p>However, that turned out to be rather tricky, mainly because the framework looks for a certain pattern of function names at module level.</p>
  
  <p>I've tried the following within the decorator, to no avail:</p>
  
  <pre><code>current_module = __import__(__name__)
  new_name = prefix + func.__name__ + suffix
  # method A
  current_module[new_name] = func
  # method B
  func.__name__ = new_name
  current_module += func
  </code></pre>
  
  <p>Any help would be appreciated!</p>