Shortcuts

mmengine.fileio.dict_from_file

mmengine.fileio.dict_from_file(filename, key_type=<class 'str'>, encoding='utf-8', file_client_args=None, backend_args=None)[源代码]

Load a text file and parse the content as a dict.

Each line of the text file will be two or more columns split by whitespaces or tabs. The first column will be parsed as dict keys, and the following columns will be parsed as dict values.

dict_from_file supports loading a text file which can be storaged in different backends and parsing the content as a dict.

参数:
  • filename (str) – Filename.

  • key_type (type) – Type of the dict keys. str is user by default and type conversion will be performed if specified.

  • encoding (str) – Encoding used to open the file. Defaults to utf-8.

  • 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.

示例

>>> dict_from_file('/path/of/your/file')  # disk
{'key1': 'value1', 'key2': 'value2'}
>>> dict_from_file('s3://path/of/your/file')  # ceph or petrel
{'key1': 'value1', 'key2': 'value2'}
返回:

The parsed contents.

返回类型:

dict

Read the Docs v: latest
Versions
latest
stable
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.