MMpy.filetools.ContextManager
Syntax
MMpy.filetools.ContextManager(file_name, directory=None)
Description
A resource management class for MMpy.File objects that may be used with the Python with
keyword.
Parameters
Name | Type | Description |
---|---|---|
file_name | string | The name and extension of the file to open. |
directory | string (optional) | The path to the directory that contains file_name. Defaults to MMpy.Project.path() |
Returns
Type |
Description |
---|---|
MMpy.File |
The opened file object. |
Notes
Context Manager is a wrapper around MMpy.File.open and MMpy.File.close that simplifies file access.
Examples
with MMpy.filetools.ContextManager("some_file.DAT") as file: # file is open print(len(file)) # file is closed
Resource ID
IDPH_FILETOOLS_CONTEXT_MANAGER