Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)

        def safeimport(name):
    modules = sys.modules.copy()
    try:
        if name in sys.modules:
            return reload(sys.modules[name])
        else:
            return __import__(name, globals(), locals(), [""])
    except:
        for name in sys.modules.copy():
            if not name in modules:
                del sys.modules[name]
        


src/c/i/circuits-3.0.0.dev/tests/core/test_utils.py   circuits(Download)
def test_safeimport(tmpdir):
    from circuits.core.utils import safeimport
 
    sys.path.insert(0, str(tmpdir))
 
    foo_path = tmpdir.ensure("foo.py")
    foo_path.write(FOO)
 
    foo = safeimport("foo")
    foo_path.write(FOOBAR)
 
    foo = safeimport("foo")
    assert foo is None
    assert foo not in sys.modules