utils.py
cpas_toolbox.utils ¶
This module provides miscellaneous utility functions.
str_to_object ¶
Try to find object with a given name.
First scope of calling function is checked for the name, then current environment (in which case name has to be a fully qualified name). In the second case, the object is imported if found.
PARAMETER | DESCRIPTION |
---|---|
name |
Name of the object to resolve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The object which the provided name refers to. None if no object was found. |
Source code in cpas_toolbox/utils.py
resolve_path ¶
Resolves a path to a full absolute path based on search_paths.
This function considers paths of 5 different cases /... -> absolute path, nothing todo ~/... -> home dir, expand user ./... -> relative to current directory ../... -> relative to current parent directory ... -> relative to search paths
Current directory is not implicitly included in search paths and has to be added with "." if desired. Search paths are handled in first to last order and considered correct if file or directory exists.
Returns original path, if file does not exist.
PARAMETER | DESCRIPTION |
---|---|
path |
The path to resolve.
TYPE:
|
search_paths |
List of search paths to prepend relative paths which are not explicitly relative to current directory. If None, no search paths are assumed.
TYPE:
|
Source code in cpas_toolbox/utils.py
download ¶
Download file from URL to a specified path.