AIOFileOpen

Resumen

Opens a local or cloud file handle that supports context manager protocol.

Sintaxis

AIOFileOpen (path, {mode}, {encoding}, {mime})
ParámetroExplicaciónTipo de datos
path

The relative path from the current working directory or an absolute path (absolute vsi path for cloud).

String
mode

Specifies the mode that will be used for opening a file.

  • r—The file will be opened in read mode.
  • w—The file will be opened in write mode
  • rb—The file will be opened in binary format for reading.
  • wb—The file will be opened in binary format for writing
Nota:

Only read mode honors the encoding parameter.

(El valor predeterminado es 'r')

String
encoding

Specifies the encoding that will be used to open a file.

  • utf-8—UTF-8 encoding will be used. This is the default.
  • utf-16—UTF-16 encoding will be used.
  • ascii—ASCII encoding will be used.

(El valor predeterminado es 'utf-8')

String
mime

The Multipurpose Internet Mail Extensions (MIME) headers. For faster creation and setting of metadata, set MIME headers when creating the file.

(El valor predeterminado es None)

Dictionary
Valor de retorno
Tipo de datosExplicación
Object

Returns the file handler as an AIOFile object.

Muestra de código

# For opening a file in the cloud store
with AIOFileOpen(r"C:\data\datacloud.acs\datafile.txt", 'r') as rcsfile:
    rcsfile.seek(5)
    rcsfile.tell()
    print(rcsfile.read(4))
# For opening a local file
with AIOFileOpen(r"C:\data\datafile.txt", 'r') as rcsfile:
    rcsfile.seek(5)
    rcsfile.tell()
    print(rcsfile.read(4))