本文整理汇总了Python中pathlib.Path.joinpath方法的典型用法代码示例。如果您正苦于以下问题:Python Path.joinpath方法的具体用法?Python Path.joinpath怎么用?Python Path.joinpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pathlib.Path
的用法示例。
在下文中一共展示了Path.joinpath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: console
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import joinpath [as 别名]
def console(self,log_options:dict={}):
'''日志输出设置
日志的输出格式为:行号 时间 级别::路径->文件名->函数名=>消息
日志添加两个:一个是文本日志记录,一个用于控制台输出
'''
log_config = OrderedDict({
'level':logging.ERROR,
'filename':'',
'datefmt':'%Y-%m-%d %H:%M:%S',
'filemode':'a',
'format':'%(lineno)d %(asctime)s@%(levelname)s::%(pathname)s->%(filename)s->%(funcName)s=>%(message)s'
})
log_config.update(log_options) if log_options else None
logging.basicConfig(**log_config)
file_log = logging.FileHandler(Path.joinpath(Path.cwd(),f'{Path(__file__).name.split(".")[0]}-log.txt'))
console_log = logging.StreamHandler()
console_log.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
logger.addHandler(file_log)
logger.addHandler(console_log)
示例2: create_absolute_csv
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import joinpath [as 别名]
def create_absolute_csv(dir_path, file_name, order_type):
""" Creates a filepath given a directory and file name.
:param dir_path: Absolute or relative path to the directory the file will be written.
:type dir_path: str
:param file_name: An optional argument for the name of the file. If not defined, filename will be stock_orders_{current date}
:type file_name: str
:param file_name: Will be 'stock', 'option', or 'crypto'
:type file_name: str
:returns: An absolute file path as a string.
"""
path = Path(dir_path)
directory = path.resolve()
if not file_name:
file_name = "{}_orders_{}.csv".format(order_type, date.today().strftime('%b-%d-%Y'))
else:
file_name = fix_file_extension(file_name)
return(Path.joinpath(directory, file_name))
示例3: assert_pipeline_notify_match_file
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import joinpath [as 别名]
def assert_pipeline_notify_match_file(pipeline_name,
expected_notify_output_path):
"""Assert that the pipeline has the expected output to NOTIFY log.
Args:
pipeline_name: str. Name of pipeline to run. Relative to ./tests/
expected_notify_output_path: path-like. Path to text file containing
expected output. Relative to working dir.
"""
assert_pipeline_notify_output_is(
pipeline_name,
read_file_to_list(Path.joinpath(working_dir,
'pipelines',
expected_notify_output_path)))
示例4: save
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import joinpath [as 别名]
def save(self, fname=None):
"""
Method saves the intent_model parameters into <<fname>>_opt.json (or <<model_file>>_opt.json)
and intent_model weights into <<fname>>.h5 (or <<model_file>>.h5)
Args:
fname: file_path to save intent_model. If not explicitly given seld.opt["model_file"] will be used
Returns:
nothing
"""
fname = self.model_path_.name if fname is None else fname
opt_fname = str(fname) + '_opt.json'
weights_fname = str(fname) + '.h5'
opt_path = Path.joinpath(self.model_path_, opt_fname)
weights_path = Path.joinpath(self.model_path_, weights_fname)
Path(opt_path).parent.mkdir(parents=True, exist_ok=True)
# print("[ saving intent_model: {} ]".format(str(opt_path)))
Path(opt_path).parent.mkdir(parents=True, exist_ok=True)
self.model.save_weights(weights_path)
with open(opt_path, 'w') as outfile:
json.dump(self.opt, outfile)
return True
示例5: maybe_download_from_cloud
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import joinpath [as 别名]
def maybe_download_from_cloud(url, filename, subfolder=None, cache_dir=None, referesh_cache=False) -> str:
"""
Helper function to download pre-trained weights from the cloud
Args:
url: (str) URL of storage
filename: (str) what to download. The request will be issued to url/filename
subfolder: (str) subfolder within cache_dir. The file will be stored in cache_dir/subfolder. Subfolder can
be empty
cache_dir: (str) a cache directory where to download. If not present, this function will attempt to create it.
If None (default), then it will be $HOME/.cache/torch/NeMo
referesh_cache: (bool) if True and cached file is present, it will delete it and re-fetch
Returns:
If successful - absolute local path to the downloaded file
else - empty string
"""
# try:
if cache_dir is None:
cache_location = Path.joinpath(Path.home(), '.cache/torch/NeMo')
else:
cache_location = cache_dir
if subfolder is not None:
destination = Path.joinpath(cache_location, subfolder)
else:
destination = cache_location
if not os.path.exists(destination):
os.makedirs(destination, exist_ok=True)
destination_file = Path.joinpath(destination, filename)
if os.path.exists(destination_file):
logging.info(f"Found existing object {destination_file}.")
if referesh_cache:
logging.info("Asked to refresh the cache.")
logging.info(f"Deleting file: {destination_file}")
os.remove(destination_file)
else:
logging.info(f"Re-using file from: {destination_file}")
return str(destination_file)
# download file
wget_uri = url + filename
logging.info(f"Downloading from: {wget_uri} to {str(destination_file)}")
wget.download(wget_uri, str(destination_file))
if os.path.exists(destination_file):
return destination_file
else:
return ""