TextFile
#
- class biotite.TextFile[source]#
Bases:
File
Base class for all line based text files. When reading a file, the text content is saved as list of strings, one for each line. When writing a file, this list is written into the file.
- Attributes:
- lineslist
List of string representing the lines in the text file. PROTECTED: Do not modify from outside.
- copy()#
Create a deep copy of this object.
- Returns:
- copy
A copy of this object.
- classmethod read(file, *args, **kwargs)#
Parse a file (or file-like object).
- Parameters:
- filefile-like object or str
The file to be read. Alternatively a file path can be supplied.
- Returns:
- fileFile
An instance from the respective
File
subclass representing the parsed file.
- static read_iter(file)#
Create an iterator over each line of the given text file.
- Parameters:
- filefile-like object or str
The file to be read. Alternatively a file path can be supplied.
- Yields:
- linestr
The current line in the file.
- write(file)#
Write the contents of this object into a file (or file-like object).
- Parameters:
- filefile-like object or str
The file to be written to. Alternatively a file path can be supplied.
- static write_iter(file, lines)#
Iterate over the given lines of text and write each line into the specified file.
In contrast to
write()
, each line of text is not stored in an intermediateTextFile
, but is directly written to the file. Hence, this static method may save a large amount of memory if a large file should be written, especially if the lines are provided as generator.- Parameters:
- filefile-like object or str
The file to be written to. Alternatively a file path can be supplied.
- linesgenerator or array-like of str
The lines of text to be written. Must not include line break characters.