From 8227524a7c45a1ac01a7b6c4568507ee289b94a4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 21:41:45 +0200 Subject: [PATCH] class/str --- rwx/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rwx/__init__.py b/rwx/__init__.py index ee9f51e..50c7cbe 100644 --- a/rwx/__init__.py +++ b/rwx/__init__.py @@ -2,14 +2,16 @@ __version__ = "0.0.1" +from os import linesep + class Class: """Root class.""" def __repr__(self) -> str: - """Represent object variables. + """Return machine-readable state. - :return: representation + :return: state :rtype: str """ name = self.__class__.__name__ @@ -18,3 +20,14 @@ class Class: ] arguments = ", ".join(attributes) return f"{name}({arguments})" + + def __str__(self) -> str: + """Return human-readable state. + + :return: state + :rtype: str + """ + attributes = [ + f"{k} = {v}" for k, v in vars(self).items() if not k.startswith("_") + ] + return linesep.join(attributes)