title: How can a Python module be imported from a URL?
body: <p>As an experiment, I want to see how to import a Python module from a URL. The hypothetical goal here would be to import from a central location which keeps the modules up-to-date. How could this be done?</p>
  
  <p>My attempt is as follows:</p>
  
  <pre><code>&gt;&gt;&gt; import urllib
  &gt;&gt;&gt; 
  &gt;&gt;&gt; def import_URL(URL):
  ...     exec urllib.urlopen(URL) in globals()
  ... 
  &gt;&gt;&gt; import_URL("https://cdn.rawgit.com/wdbm/shijian/master/shijian.py")
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 2, in import_URL
  TypeError: exec: arg 1 must be a string, file, or code object
  </code></pre>
  
  <hr>
  
  <p>EDIT: <a href="https://stackoverflow.com/users/100297/martijn-pieters">Martijn Pieters</a> identified a fix for the example code that results in the string representation of the remote module. The resulting code is as follows:</p>
  
  <pre><code>import urllib
  def import_URL(URL):
      exec urllib.urlopen(URL).read() in globals()
  </code></pre>