本文整理匯總了Python中pathlib.Path.is_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Path.is_file方法的具體用法?Python Path.is_file怎麽用?Python Path.is_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pathlib.Path
的用法示例。
在下文中一共展示了Path.is_file方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: postFromLog
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def postFromLog(fileName):
"""Analyze a log file and return a list of dictionaries containing
submissions
"""
if Path.is_file(Path(fileName)):
content = JsonFile(fileName).read()
else:
print("File not found")
sys.exit()
try:
del content["HEADER"]
except KeyError:
pass
posts = []
for post in content:
if not content[post][-1]['TYPE'] == None:
posts.append(content[post][-1])
return posts
示例2: __init__
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def __init__(self,directory,post):
if "self" in GLOBAL.arguments.skip: raise TypeInSkip
if not os.path.exists(directory): os.makedirs(directory)
filename = GLOBAL.config['filename'].format(**post)
fileDir = directory / (filename+".md")
print(fileDir)
print(filename+".md")
if Path.is_file(fileDir):
raise FileAlreadyExistsError
try:
self.writeToFile(fileDir,post)
except FileNotFoundError:
fileDir = post['POSTID']+".md"
fileDir = directory / fileDir
self.writeToFile(fileDir,post)
示例3: get_py2exe_datafiles
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def get_py2exe_datafiles():
data_path = Path(get_data_path())
d = {}
for path in filter(Path.is_file, data_path.glob("**/*")):
(d.setdefault(str(path.parent.relative_to(data_path.parent)), [])
.append(str(path)))
return list(d.items())
示例4: list_fonts
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def list_fonts(directory, extensions):
"""
Return a list of all fonts matching any of the extensions, found
recursively under the directory.
"""
extensions = ["." + ext for ext in extensions]
return [str(path)
for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
if path.suffix in extensions]
示例5: get_thermal_image_from_file
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def get_thermal_image_from_file(thermal_input, thermal_class=CFlir, colormap=None):
'''
Function to get the image associated with each RJPG file using the FLIR Thermal base class CFlir
Saves the thermal images in the same place as the original RJPG
'''
CThermal = thermal_class
inputpath = Path(thermal_input)
if Path.is_dir(inputpath):
rjpg_img_paths = list(Path(input_folder).glob('*R.JPG'))
fff_file_paths = list(Path(input_folder).glob('*.fff'))
if len(rjpg_img_paths)>0:
for rjpg_img in tqdm(rjpg_img_paths, total=len(rjpg_img_paths)):
thermal_obj = CThermal(rjpg_img, color_map=colormap)
path_wo_ext = str(rjpg_img).replace('_R'+rjpg_img.suffix,'')
thermal_obj.save_thermal_image(path_wo_ext+'.jpg')
elif len(fff_file_paths)>0:
for fff in tqdm(fff_file_paths, total=len(fff_file_paths)):
save_image_path = str(fff).replace('.fff','.jpg')
thermal_obj = CThermal(fff, color_map=colormap)
thermal_obj.save_thermal_image(save_image_path)
else:
logger.error('Input folder contains neither fff or RJPG files')
elif Path.is_file(inputpath):
thermal_obj = CThermal(thermal_input, color_map=colormap)
path_wo_ext = Path.as_posix(inputpath).replace(inputpath.suffix,'')
thermal_obj.save_thermal_image(path_wo_ext+'.jpg')
else:
logger.error('Path given is neither file nor folder. Please check')
示例6: load
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def load(self, **kwargs) -> None:
"""Load classifier parameters"""
log.info(f"Loading model from {self.load_path}")
for path in self.load_path:
if Path.is_file(path):
self.ec_data += load_pickle(path)
else:
raise FileNotFoundError
log.info(f"Loaded items {len(self.ec_data)}")
示例7: check_target_type
# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import is_file [as 別名]
def check_target_type(target, filetype):
""" Validate path and file / directory type.
It also returns the appropritate fio command line parameter based on the
file type.
"""
keys = ['file', 'device', 'directory']
test = {
keys[0]: Path.is_file,
keys[1]: Path.is_block_device,
keys[2]: Path.is_dir
}
parameter = {
keys[0]: '--filename',
keys[1]: '--filename',
keys[2]: '--directory'
}
if not os.path.exists(target):
print(f"Benchmark target {filetype} {target} does not exist.")
sys.exit(10)
if filetype not in keys:
print(f"Error, filetype {filetype} is an unknown option.")
exit(123)
check = test[filetype]
path_target = Path(target) # path library needs to operate on path object
if check(path_target):
return parameter[filetype]
else:
print(f"Target {filetype} {target} is not {filetype}.")
sys.exit(10)