mindspore/docs/api/api_python/dataset/mindspore.dataset.utils.Lin...

38 lines
1004 B
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.dataset.utils.LineReader
==================================
.. py:class:: mindspore.dataset.utils.LineReader(filename)
基于行的文件读取器。
通过提前缓存文件基于行的元信息,实现对文件各行的随机访问读取。
参数:
- **filename** (str) - 待读取的文件名。
异常:
- **TypeError** - `filename` 无效。
- **RuntimeError** - `filename` 不存在或者不是常规文件。
.. py:method:: close()
关闭文件句柄。
.. py:method:: len()
获取当前文件的总行数。
.. py:method:: readline(line)
读取指定行的内容。
参数:
- **line** (int) - 待读取的行号起始行号为1。
返回:
str对应行的内容不包含换行符。
异常:
- **TypeError** - 如果 `line` 不是int类型。
- **ValueError** - 如果 `line` 取值大于文件总行数。