Python pathlib.Path.joinpath() Examples
The following are 5
code examples of pathlib.Path.joinpath().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pathlib.Path
, or try the search function
.
Example #1
Source File: export.py From robin_stocks with MIT License | 6 votes |
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))
Example #2
Source File: SDK基类.py From TSDK with MIT License | 6 votes |
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)
Example #3
Source File: pipeline_runner.py From pypyr-cli with Apache License 2.0 | 5 votes |
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)))
Example #4
Source File: multiclass.py From intent_classifier with Apache License 2.0 | 5 votes |
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
Example #5
Source File: helpers.py From NeMo with Apache License 2.0 | 4 votes |
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 ""