title: Changing function module
body: <p>I've got 2 modules A and B.
  module A has nothing inside and module B has a function 'f'
  I want to assign function 'f' to module A, but I want override this functions <strong>globals</strong>, because I want this function to use A module variables.</p>
  
  <p>But there I've got some problems. with this simple code:</p>
  
  <pre><code>print A
  print B
  print '---'
  from copy import deepcopy 
  setattr(A, 'f', deepcopy(B.f))
  A.f.__module__ = A
  A.f.__globals__['__name__'] = 'A'
  print A
  print B
  </code></pre>
  
  <p>I've got following result:</p>
  
  <pre><code>&lt;module 'A' from '&lt;path&gt;/A/__init__.pyc'&gt;
  &lt;module 'B' from '&lt;path&gt;/B/__init__.pyc'&gt;
  ---
  &lt;module 'A' from '&lt;path&gt;/A/__init__.pyc'&gt;
  &lt;module 'A' from '&lt;path&gt;/B/__init__.pyc'&gt;
  </code></pre>
  
  <p>Why the name of module is changing when I'm changing only one of functions <strong>globals</strong> key and how can I prevent it?</p>