本文整理匯總了Python中imp.load_package方法的典型用法代碼示例。如果您正苦於以下問題:Python imp.load_package方法的具體用法?Python imp.load_package怎麽用?Python imp.load_package使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imp
的用法示例。
在下文中一共展示了imp.load_package方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_load_package
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import load_package [as 別名]
def test_load_package(self):
import testpkg1
pkg = imp.load_package('libcopy', testpkg1.__path__[0])
self.assertEqual(sys.modules['libcopy'], pkg)
pkg = imp.load_package('some_new_pkg', 'some_path_that_does_not_and_never_will_exist')
self.assertEqual(sys.modules['some_new_pkg'], pkg)
示例2: test_load_package
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import load_package [as 別名]
def test_load_package(self):
import testpkg1
pkg = imp.load_package('libcopy', testpkg1.__path__[0])
self.assertEqual(sys.modules['libcopy'], pkg)
with self.assertRaises(AttributeError): # AttributeError: 'NoneType' object has no attribute 'name'
imp.load_package('some_new_pkg', 'some_path_that_does_not_and_never_will_exist')
示例3: setup
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import load_package [as 別名]
def setup(base_path, root_module_name="lpt"):
if sys.modules.has_key(root_module_name):
# already set up
return
_create_module_and_parents(root_module_name)
imp.load_package(root_module_name, base_path)
# Allow locally installed third party packages to be found.
# This is primarily for the benefit of frontend and tko so that they
# may use libraries other than those available as system packages.
sys.path.insert(0, os.path.join(base_path, "site-packages"))