FileScope
#
- class ansys.tools.variableinterop.file_scope.FileScope#
Bases:
contextlib.AbstractContextManager
,abc.ABC
Provides 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.
FileValue
instances (except foransys.tools.variableinterop.EMPTY_FILE
) should always be created by aFileScope
instance.FileValue
instances created by aFileScope
instance are not valid once theFileScope
instance has been closed.This abstract base class contains the logic to be a context manager for use in
with
blocks. Any derived class’sclose
method is automatically called when thewith
block 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.
- abstract 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
FileValue
object 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:
FileValue
New
FileValue
object with the contents of the specified file, backed by this scope.
- abstract 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
FileScope
instance from a map of API strings.