You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
752 B
Python
28 lines
752 B
Python
"""Реализация простого класса для чтения из файла"""
|
|
|
|
|
|
class FileReader:
|
|
"""Реализация класса для чтения из файла"""
|
|
|
|
def __init__(self, file_path: "str"):
|
|
"""Конструктор класса"""
|
|
|
|
self.file_path: "str" = file_path
|
|
|
|
def __repr__(self) -> "str":
|
|
"""Строковое представления объекта"""
|
|
|
|
return f"FileReader({self.file_path!r})"
|
|
|
|
def read(self) -> "str":
|
|
"""Чтение файла"""
|
|
|
|
try:
|
|
with open(self.file_path, encoding="utf-8") as des:
|
|
content: "str" = des.read()
|
|
|
|
except IOError:
|
|
content = ""
|
|
|
|
return content
|