tepkit.io.File

tepkit.io.File#

class tepkit.io.File#

The base class for all files.

Attributes#

Attribute

Default Value

Description

default_dir_path

'./'

The default path of located directory of file when use from_dir() .

default_file_name

None

The default name of file when use from_dir() .

source_path

None

Record the path of the file when use from_file() or from_dir() .

Methods#

from_file(→ tepkit.utils.typing_tools.Self)

Read a file by its path .

from_dir(→ tepkit.utils.typing_tools.Self)

Read a file named cls.default_file_name in the cls.default_dir_path.

to_file(path)

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() or from_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 the cls.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.