摘要
打开支持上下文管理器协议的本地或云文件句柄。
语法
AIOFileOpen (path, {mode}, {encoding}, {mime})
参数 | 说明 | 数据类型 |
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.
注:Only read mode honors the encoding parameter. (默认值为 'r') | String |
encoding | Specifies the encoding that will be used to open a file.
(默认值为 '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. (默认值为 None) | Dictionary |
数据类型 | 说明 |
Object | 以 AIOFile 对象形式返回文件句柄。 |
代码示例
# 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))