tepkit.io.File#
- class tepkit.io.File#
The base class for all files.
Attributes#
Attribute |
Default Value |
Description |
---|---|---|
|
|
The default path of located directory of file when use |
|
|
The default name of file when use |
|
|
Record the path of the file when use |
Methods#
|
Read a file by its |
|
Read a file named |
|
Write the data of the object to a file. |
All Members#
- default_dir_path: PathLike = './'
The default path of located directory of file when use
from_dir()
.
- default_file_name: str = None
The default name of file when use
from_dir()
.
- source_path: pathlib.Path | None = None
Record the path of the file when use
from_file()
orfrom_dir()
.
- classmethod from_file(path: tepkit.utils.typing_tools.PathLike) Self
Read a file by its
path
.>>> file1 = File.from_file("example.txt") >>> file2 = File.from_file("../example.txt")
- classmethod from_dir(path: tepkit.utils.typing_tools.PathLike = None, file_name: str = None) Self
Read a file named
cls.default_file_name
in thecls.default_dir_path
.>>> file1 = File.from_dir()
You can also specify the dirctory path or the file name:
>>> file2 = File.from_dir("./result") >>> file3 = File.from_dir(file_name = "file_name.txt") >>> file4 = File.from_dir("./result", file_name = "file_name.txt")
- abstract classmethod to_file(path: tepkit.utils.typing_tools.PathLike)
Write the data of the object to a file.