NamedTempFolder
ClassContextSource
NamedTempFolder(folder_path: str | PathLike[str] | None = None)
Named temporary folder.
Similar to tempfile.NamedTemporaryFile. This context maintain a temporary folder that can be accessed by the path. When exiting from the context, the temporary folder will be automatically deleted.
Arguments
Requires
| Name | Type | Required | |
|---|---|---|---|
folder_path | str | PathLike[str] | None | The path to the temporary folder. If not specified, will use Note that if the specified folder path exists, will automatically add postfix to the given path until a new folder can be maintained. |
Methods
close
self.close()
Close the temporary folder. Will delete the folder and reset the status to the status that is not in the context.
This method will be automatically called when exiting from this context.
Properties
current_path
current_path: str | None = self.current_path
Get the current temporary folder path. If not in the context,
this value will be None.
Operators
__enter__
with self as v_1:
v_1: str
Enter the context.
Returns
| Name | Type | |
|---|---|---|
v_1 | str | The current path of the temporary folder. |
__exit__
v_1: bool | None = self.__exit__(
exc_type: type[_BaseException] | None,
exc_value: _BaseException | None,
traceback: TracebackType | None,
)
Raise any exception triggered within the runtime context.
Requires
| Name | Type | Required | |
|---|---|---|---|
exc_type | type[_BaseException] | None | The type of the exception (if existing). | |
exc_value | _BaseException | None | The instance of the exception (if existing). | |
traceback | TracebackType | None | The traceback stack of the exception (if existing). |
Returns
| Name | Type | |
|---|---|---|
v_1 | bool | None | Whether to catch the exception. For this context, it will be always None. |