hup.io.plain module¶
File I/O for plain text files.
-
get_comment
(file: Union[IO[Any], os.PathLike, hup.io.abc.Connector]) → str¶ Read initial comment lines from text file.
Parameters: file – File reference to a file object. The reference can ether be given as a String or path-like object, that points to a valid entry in the file system, a file accessor
or an opened file object in reading mode.Returns: String containing the header of given text file.
-
get_content
(file: Union[IO[Any], os.PathLike, hup.io.abc.Connector], lines: int = 0) → List[str]¶ Read non-blank non-comment lines from text file.
Parameters: - file – File reference to a file object. The reference can
ether be given as a String or path-like object, that points
to a valid entry in the file system, a
file accessor
or an opened file object in reading mode. - lines – Number of content lines, that are returned. By default all lines are returned.
Returns: List of strings containing non-blank non-comment lines.
- file – File reference to a file object. The reference can
ether be given as a String or path-like object, that points
to a valid entry in the file system, a
-
get_name
(file: Union[IO[Any], os.PathLike, hup.io.abc.Connector]) → Optional[str]¶ Get name of referenced file object.
Parameters: file – File reference to a file object. The reference can ether be given as a String or path-like object, that points to a valid entry in the file system, a file accessor
or an opened file object in reading or writing mode.Returns: String containing the name of the referenced file object or None if the name could not be determined.
-
load
(file: Union[IO[Any], os.PathLike, hup.io.abc.Connector]) → str¶ Load text from file.
Parameters: file – File reference to a file object. The reference can ether be given as a String or path-like object, that points to a valid entry in the file system, a file accessor
or an opened file object in reading or writing mode.Returns: Content of the given file as text.
-
openx
(file: Union[IO[Any], os.PathLike, hup.io.abc.Connector], mode: str = 'rt') → Iterator[io.TextIOBase]¶ Contextmanager to provide a unified interface to text files.
This context manager extends the standard implementation of
open()
by allowing the passed argument file to be a str or path-like object, which points to a valid filename in the directory structure of the system, or a file object. If the file argument is a str or a path-like object, the given path may contain application variables, like ‘%home%’ or ‘%user_data_dir%’, which are extended before returning a file handler to a text file. Afterwards, when exiting the with statement, the file is closed. If the argument file, however, is a file-like object, the file is not closed, when exiting the with statement.Parameters: - file – File reference to a file object. The reference can
ether be given as a String or path-like object, that points
to a valid entry in the file system, a
file accessor
or an opened file object in reading or writing mode. - mode – String, which characters specify the mode in which the file stream is wrapped. The default mode is reading mode. Suported characters are: ‘r’: Reading mode (default) ‘w’: Writing mode
Yields: text file in reading or writing mode.
- file – File reference to a file object. The reference can
ether be given as a String or path-like object, that points
to a valid entry in the file system, a
-
save
(text: str, file: Union[IO[Any], os.PathLike, hup.io.abc.Connector]) → None¶ Save text to file.
Parameters: - text – Text given as string
- file – File reference to a file object. The reference can
ether be given as a String or path-like object, that points
to a valid entry in the file system, a
file accessor
or an opened file object in writing mode.