Save the arguments in the specified directory as - a text file called 'args.txt' - a pickle file called 'args.pickle' :param args: The arguments to be saved :param directory_path: The path to the directory where the arguments should be saved
(args: argparse.Namespace, directory_path: str)
| 155 | return milestones_list |
| 156 | |
| 157 | def save_args(args: argparse.Namespace, directory_path: str) -> None: |
| 158 | """ |
| 159 | Save the arguments in the specified directory as |
| 160 | - a text file called 'args.txt' |
| 161 | - a pickle file called 'args.pickle' |
| 162 | :param args: The arguments to be saved |
| 163 | :param directory_path: The path to the directory where the arguments should be saved |
| 164 | """ |
| 165 | # If the specified directory does not exists, create it |
| 166 | if not os.path.isdir(directory_path): |
| 167 | os.mkdir(directory_path) |
| 168 | # Save the args in a text file |
| 169 | with open(directory_path + '/args.txt', 'w') as f: |
| 170 | for arg in vars(args): |
| 171 | val = getattr(args, arg) |
| 172 | if isinstance(val, str): # Add quotation marks to indicate that the argument is of string type |
| 173 | val = f"'{val}'" |
| 174 | f.write('{}: {}\n'.format(arg, val)) |
| 175 | # Pickle the args for possible reuse |
| 176 | with open(directory_path + '/args.pickle', 'wb') as f: |
| 177 | pickle.dump(args, f) |
| 178 | |
| 179 | |
| 180 | def load_args(directory_path: str) -> argparse.Namespace: |
no outgoing calls
no test coverage detected