Skip to main content

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​

NameTypeRequired
Description
folder_pathstr | PathLike[str] | None

The path to the temporary folder. If not specified, will use tempfile.mkdtemp() to create the folder.

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​

NameType
Description
v_1strThe 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​

NameTypeRequired
Description
exc_typetype[_BaseException] | NoneThe type of the exception (if existing).
exc_value_BaseException | NoneThe instance of the exception (if existing).
tracebackTracebackType | NoneThe traceback stack of the exception (if existing).

Returns​

NameType
Description
v_1bool | NoneWhether to catch the exception. For this context, it will be always None.