molgri.logfiles
Logging. Naming of files with first free index.
Functions
|
Problem: you want to save a file with a certain name, eg. |
|
Similar to find_first_free_index, but you have a list of files (eg. |
|
Args: |
|
Classes
|
|
|
- class molgri.logfiles.AbstractLogger(path: str, level: str = 'INFO')
- __init__(path: str, level: str = 'INFO')
- abstract log_set_up(investigated_object: object)
- molgri.logfiles.first_index_free_4_all(list_names, list_endings, list_paths, index_places: int = 4) int
Similar to find_first_free_index, but you have a list of files (eg. trajectory, topology, log) -> all must be still free to use this specific index.
- molgri.logfiles.paths_free_4_all(list_names, list_endings, list_paths, index_places: int = 4) tuple
- molgri.logfiles.find_first_free_index(name: str, ending: str | None = None, index_places: int = 4, path: str = '') int
Problem: you want to save a file with a certain name, eg. pics/PrettyFigure.png, but not overwrite any existing files.
Solution: this function checks if the given file already exists and increases the index until a unique one is found. So for our example it may return the string pics/PrettyFigure_007.png
If no such file exists yet, the return string will include as many zeros as defined by index_places
- Args:
path: path to appropriate directory (if not current), ending with /, in the example ‘pics/’ name: name of the file, in the example ‘PrettyFigure’ ending: in the example, select ‘png’ (NO DOT) index_places: how many places are used for the number
- Returns:
number - first free index (can be forwarded to format_name)
- molgri.logfiles.format_name(file_name: str, num: int | None = None, places_num: int = 4, suffix: str | None = None, file_path: str = '')
- Args:
file_path: eg. output/ file_name: eg my_file num: eg 17 places_num: eg 4 -> num will be formatted as 0017 suffix: ending of the file
- Returns:
full path and file name in correct format