view python/ @ 168:09c748a71b1b

handle overlapping files
author Jeff Hammel <>
date Mon, 26 Sep 2011 16:33:02 -0700
parents f145d7b1fbf7
children 691b508084f1
line wrap: on
line source

def require(url):
    import a module from the web
    url should be like scheme://
    import imp
    import os
    import tempfile
    import urllib2
    contents = urllib2.urlopen(url).read()
    filename = url.rsplit('/', 1)[-1]
    module = filename.rsplit('.', 1)[-1]
    dest = tempfile.mkstemp(suffix='.py', prefix=module)
    f = file(dest, 'w')
    return imp.load_source(module, dest)

# TODO: make an equivalent method for a tarball