Utilities related to files¶
Files¶
-
researchutils.files.create_dir_if_not_exist(outdir)[source]¶ Check directory existence and creates new directory if not exist
Parameters: outdir (string) – Path of the file to create directory Raises: RuntimeError– File exists in outdir but it is not a directory
-
researchutils.files.file_exists(path)[source]¶ Check file existence on given path
Parameters: path (string) – Path of the file to check existence Returns: file_existence – True if file exists otherwise False Return type: bool
-
researchutils.files.load_pickle(file_path)[source]¶ Load pickled data from file
Parameters: file_path (string) – Path of the file to load pickled data Returns: data Return type: data pickled in file
-
researchutils.files.prepare_output_dir(base_dir, args, time_format='%Y-%m-%d-%H%M%S')[source]¶ Prepare a directory with current datetime as name. Created directory contains the command and args when the script was called as text file.
Parameters: - base_dir (string) – Path of the directory to save data
- args (dictionary) – Arguments when the python script was called
- time_format (string) – Datetime format string for naming directory to save data
Returns: out_dir
Return type: directory to save data
-
researchutils.files.read_text_from_file(file_path)[source]¶ Read given file as text
Parameters: file_path (string) – Path of the file to read data Returns: data – Text read from the file Return type: string