本文整理匯總了Python中folder.Folder.file_exists方法的典型用法代碼示例。如果您正苦於以下問題:Python Folder.file_exists方法的具體用法?Python Folder.file_exists怎麽用?Python Folder.file_exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類folder.Folder
的用法示例。
在下文中一共展示了Folder.file_exists方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from folder import Folder [as 別名]
# 或者: from folder.Folder import file_exists [as 別名]
class PluginFolder:
''' represents the plugins folder '''
def __init__(self, pythonic_path):
self.pythonic_path = pythonic_path
self.folder = Folder(os.path.dirname(__file__) + "/" + self.pythonic_path.replace(".", "/"))
# returns a list of plugin names
def enumerate(self):
return [ fname[:-3] for fname in self.folder.list_file_names() if fname.endswith(".py") ]
# returns a module object representing a loaded plugin
def load(self, plugin_name):
if not self.folder.file_exists(plugin_name + ".py"):
raise ImportError("module name \"{}\" not found".format(plugin_name))
# create pythonic path
prefix = self.pythonic_path
if prefix != "":
prefix += "."
full_module_name = prefix + plugin_name
# now no path is needed
module_obj = __import__(full_module_name)
# browse through the python module tree
for next_dive in full_module_name.split(".")[1:]:
module_obj = getattr(module_obj, next_dive)
return module_obj