FileScope#
- class ansys.tools.variableinterop.file_scope.FileScope#
Bases:
contextlib.AbstractContextManager,abc.ABCProvides an abstract base for file scopes.
A file scope helps a program manage the disk space used for file storage and enables it to clean up caches and space in a reliable way.
FileValueinstances (except foransys.tools.variableinterop.EMPTY_FILE) should always be created by aFileScopeinstance.FileValueinstances created by aFileScopeinstance are not valid once theFileScopeinstance has been closed.This abstract base class contains the logic to be a context manager for use in
withblocks. Any derived class’sclosemethod is automatically called when thewithblock is exited.
Overview#
Close the |
|
Read the contents of a file and create a new |
|
Create a |
Raise any exception triggered within the runtime context. |
Import detail#
from ansys.tools.variableinterop.file_scope import FileScope
Method detail#
- FileScope.__exit__(__exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: types.TracebackType | None) bool | None#
Raise any exception triggered within the runtime context.
- abstractmethod FileScope.close() None#
Close the
FileScopeinstance, cleaning up any files it contains.
- abstractmethod FileScope.read_from_file(to_read: os.PathLike, mime_type: str | None = None, encoding: str | None = None) ansys.tools.variableinterop.file_value.FileValue#
Read the contents of a file and create a new
FileValueobject backed by a file in this scope.- Parameters:
- to_read
PathLike Path to the file to read.
- mime_type
Optional[str],optional MIME type of the file. The default is None, which indicates that the file does not have a MIME type or that the type is not known.
- encoding
Optional[str],optional Encoding of the file. The default is None, which indicates that the file does not have a text encoding (for example, because it is a binary file.)
- to_read
- Returns:
FileValueNew
FileValueobject with the contents of the specified file, backed by this scope.
- abstractmethod FileScope.from_api_object(api_object: Dict[str, str | None], load_context: ansys.tools.variableinterop.isave_context.ILoadContext) ansys.tools.variableinterop.file_value.FileValue#
Create a
FileScopeinstance from a map of API strings.