title: Pass package/module as argument in Python
body: <p>Suppose I write some plotting program. This program depends on a module that can draw graphics primitives. But that graphics module could be <em>anything</em> that supports the used operations. It could be a module that plots on screen or writes to a file format or controls a robot with a pen.</p>
  
  <p>I'd like to dynamically switch that module. In C++, one would typically use the abstract factory pattern: The plotting program receives a factory as a parameter from where it constructs the desired graphics primitives. It would be perfectly feasible to implement the factory pattern also in Python.</p>
  
  <p>But - would it be a good idea to just use the package as a parameter? From the pure technical perspective, a program like following would work:</p>
  
  <pre><code>import screen_graphics
  import robot_graphics
  
  def my_plot_prog(graphics_lib):
     ...
  
  my_plot_prog(screen_graphics) # plot on screen
  my_plot_prog(robot_graphics) # R/C robot with a pen
  </code></pre>
  
  <p>Can I do it like that or are there some serious pitfalls or better approaches?</p>