Shortcuts

mmengine.fileio.dump

mmengine.fileio.dump(obj, file=None, file_format=None, file_client_args=None, backend_args=None, **kwargs)[源代码]

Dump data to json/yaml/pickle strings or files.

This method provides a unified api for dumping data as strings or to files, and also supports custom arguments for each file format.

dump supports dumping data as strings or to files which is saved to different backends.

参数:
  • obj (any) – The python object to be dumped.

  • file (str or Path or file-like object, optional) – If not specified, then the object is dumped to a str, otherwise to a file specified by the filename or file-like object.

  • file_format (str, optional) – Same as load().

  • file_client_args (dict, optional) – Arguments to instantiate a FileClient. See mmengine.fileio.FileClient for details. Defaults to None. It will be deprecated in future. Please use backend_args instead.

  • backend_args (dict, optional) – Arguments to instantiate the prefix of uri corresponding backend. Defaults to None. New in v0.2.0.

示例

>>> dump('hello world', '/path/of/your/file')  # disk
>>> dump('hello world', 's3://path/of/your/file')  # ceph or petrel
返回:

True for success, False otherwise.

返回类型:

bool