title: Encapsulate the scope of an imported module
body: <p>Using the <a href="http://downloads.ionmc.com/code/roboclaw_python.zip" rel="nofollow noreferrer">hideous RoboClaw Python "library"</a> in a project, I can't seem to get past the fact that they threw a bunch of functions and global variables that deal with interfacing with physical hardware into a file.  Unfortunately, I am stuck using this library because when the vendor releases a new firmware for their board, they also update this file on their website; porting it to something useful would be a continuous effort.</p>
  
  <p>The issue arises when I attempt to import it multiple times, once for each board that I have attached to USB.  Something (conceptually) like this would be ideal:</p>
  
  <pre><code>import roboclaw
  class Board:
      def __init__(self):
          self.rc = roboclaw
  </code></pre>
  
  <p>Since the Python interpreter seems to maintain the same module reference in memory with every import, I can't seem to get it to create instances that exist in separate namespaces, essentially spitting out all kinds of I/O conflict errors when all boards incorrectly become assigned to the same <code>/dev/ttyACM</code> device file.  The closest that I seem to be able to get is <a href="https://stackoverflow.com/a/16719281/2962917">this answer provided by Noctis Skytower</a>, but it still isn't creating a separate namespaces for each <code>Board</code> instance.</p>
  
  <p>Additionally, I have tried setting up dynamic imports using <code>imp</code> (like <a href="https://stackoverflow.com/a/11285504/2962917">this</a>) and <code>importlib</code> (like <a href="https://stackoverflow.com/a/16424060/2962917">this</a>) though both of these fail to import because they can't find the <code>roboclaw.py</code> file that sits in the same directory.</p>
  
  <p>At a bit of a loss for the direction that I should be going on this, as I've never had to deal with this before.</p>