open_file

This API supports only the MindSpore framework.

Function

with is used to call open_file to open a file in read-only mode and return the corresponding _ReadableFileWrapper instance. The instance provides the read() and close() methods.

  • read: reads file content.
    read(self, offset=0, count=-1)

    Parameter

    Mandatory/Optional

    Description

    Value

    offset

    Optional

    Offset of the file to be read.

    count + offset ≤ file_size

    [0, file_size)

    count

    Optional

    Size of the file to be read.

    count + offset ≤ file_size

    • -1: Read the entire file.
    • (0, file_size]
  • close: closes a file.
    This method is automatically called when with exits the context.
    close(self)

Format

mindio_acp.open_file(path: str)

Parameters

Parameter

Mandatory/Optional

Description

Value

path

Mandatory

Loading path

Valid file path

Usage Example

>>> with mindio_acp.open_file('/mnt/dpc01/checkpoint/rank-0.pt') as f:
...     read_data = f.read()

Return Value

_ReadableFileWrapper instance.

For details, see MindSpore documentation.