find_path
(函数来自 pyomo.common.fileutils)
- pyomo.common.fileutils.find_path(name, validate, cwd=True, mode=4, ext=None, pathlist=[], allow_pathlist_deep_references=True)[source]
根据一组搜索参数定位路径
- Parameters:
name (str) – 要定位的名称。名称可能包含对用户主目录的引用(
~user)、环境变量(${HOME}/bin)和 shell 通配符(?和*);所有这些都将被展开。validate (function) – 一个用于验证路径的函数(由 find_file 和 find_dir 使用以区分文件和目录)
cwd (bool) – 首先在当前工作目录中查找 [默认值: True]
mode (mask) – 如果不为 None,则只返回可以读取/写入/执行的条目。有效值是 {os.R_OK, os.W_OK, os.X_OK} 的包含 OR [默认:
os.R_OK]ext (str 或 iterable 的 str) – 如果不为 None,则同时查找 name+ext [默认值: None]
pathlist (str 或 iterable 的 str) – 包含要搜索路径的字符串列表,每个字符串包含一个路径。如果 pathlist 是一个字符串,则首先使用 os.pathsep 进行分割以生成 pathlist [默认值:
[]]。allow_pathlist_deep_references (bool) – 如果 allow_pathlist_deep_references 为 True 且名称 看起来是相对路径,则允许相对于 pathlist 中的目录进行深度引用匹配 (例如,如果名称是
foo/my.exe且/usr/bin在 pathlist 中,那么find_file()可能会返回/usr/bin/foo/my.exe)。如果 allow_pathlist_deep_references 为 False 且名称看起来 是相对路径,则只允许相对于当前目录的匹配(假设 cwd==True)。[默认值:True]
注释
find_path 使用 glob,因此路径和/或名称可能包含通配符。返回第一个匹配的条目。