Shortcuts

Note

You are reading the documentation for MMOCR 0.x, which will soon be deprecated by the end of 2022. We recommend you upgrade to MMOCR 1.0 to enjoy fruitful new features and better performance brought by OpenMMLab 2.0. Check out the maintenance plan, changelog, code and documentation of MMOCR 1.0 for more details.

Source code for mmocr.utils.fileio

# Copyright (c) OpenMMLab. All rights reserved.
import os

import mmcv


[docs]def list_to_file(filename, lines): """Write a list of strings to a text file. Args: filename (str): The output filename. It will be created/overwritten. lines (list(str)): Data to be written. """ mmcv.mkdir_or_exist(os.path.dirname(filename)) with open(filename, 'w', encoding='utf-8') as fw: for line in lines: fw.write(f'{line}\n')
[docs]def list_from_file(filename, encoding='utf-8'): """Load a text file and parse the content as a list of strings. The trailing "\\r" and "\\n" of each line will be removed. Note: This will be replaced by mmcv's version after it supports encoding. Args: filename (str): Filename. encoding (str): Encoding used to open the file. Default utf-8. Returns: list[str]: A list of strings. """ item_list = [] with open(filename, 'r', encoding=encoding) as f: for line in f: item_list.append(line.rstrip('\n\r')) return item_list
Read the Docs v: v0.6.3
Versions
latest
stable
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
v0.1.0
dev-1.x
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.