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:    From robin_stocks with MIT License 6 votes vote down vote up
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,'%b-%d-%Y'))
        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 vote down vote up
def console(self,log_options:dict={}):
        日志的输出格式为:行号 时间 级别::路径->文件名->函数名=>消息
        log_config = OrderedDict({
            'datefmt':'%Y-%m-%d %H:%M:%S',
            '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
        file_log = logging.FileHandler(Path.joinpath(Path.cwd(),f'{Path(__file__).name.split(".")[0]}-log.txt'))

        console_log = logging.StreamHandler()

        logger = logging.getLogger(__name__)
Example #3
Source File:    From pypyr-cli with Apache License 2.0 5 votes vote down vote up
def assert_pipeline_notify_match_file(pipeline_name,
    """Assert that the pipeline has the expected output to NOTIFY log.

        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.
Example #4
Source File:    From intent_classifier with Apache License 2.0 5 votes vote down vote up
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)
            fname: file_path to save intent_model. If not explicitly given seld.opt["model_file"] will be used

        fname = 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)


        with open(opt_path, 'w') as outfile:

            json.dump(self.opt, outfile)

        return True 
Example #5
Source File:    From NeMo with Apache License 2.0 4 votes vote down vote up
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
        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

        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')
        cache_location = cache_dir
    if subfolder is not None:
        destination = Path.joinpath(cache_location, subfolder)
        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):"Found existing object {destination_file}.")
        if referesh_cache:
  "Asked to refresh the cache.")
  "Deleting file: {destination_file}")
  "Re-using file from: {destination_file}")
            return str(destination_file)
    # download file
    wget_uri = url + filename"Downloading from: {wget_uri} to {str(destination_file)}"), str(destination_file))
    if os.path.exists(destination_file):
        return destination_file
        return ""