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)[源代码]¶
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.- 参数
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 usebackend_args
instead.backend_args (dict, optional) – Arguments to instantiate the prefix of uri corresponding backend. Defaults to None. New in v0.2.0.
实际案例
>>> list_from_file('/path/of/your/file') # disk ['hello', 'world'] >>> list_from_file('s3://path/of/your/file') # ceph or petrel ['hello', 'world']