Shortcuts

mmengine.fileio.list_from_file

mmengine.fileio.list_from_file(filename, prefix='', offset=0, max_num=0, encoding='utf-8', file_client_args=None, backend_args=None)[source]

Load a text file and parse the content as a list of strings.

list_from_file supports loading a text file which can be storaged in different backends and parsing the content as a list for strings.

Parameters
  • filename (str) – Filename.

  • prefix (str) – The prefix to be inserted to the beginning of each item.

  • offset (int) – The offset of lines.

  • max_num (int) – The maximum number of lines to be read, zeros and negatives mean no limitation.

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

Examples

>>> list_from_file('/path/of/your/file')  # disk
['hello', 'world']
>>> list_from_file('s3://path/of/your/file')  # ceph or petrel
['hello', 'world']
Returns

A list of strings.

Return type

list[str]

Read the Docs v: v0.8.3
Versions
latest
stable
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
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.