Skip to content

Commit

Permalink
[Chore]: Add OOP-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsfoss0 committed Apr 14, 2023
1 parent cc47ca7 commit 0aef2c7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python-incubation/0x04-oop_python/oop_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ def __setattr__(self, name, value):
else:
self.__dict__[name] = value

def __delattr__(self, attr_name):
if attr_name in self.__dict__.keys():
del self.__dict__[attr_name]
return f"'{attr_name}' deleted"
else:
return "Cannot delete '{}', it doesn't exist".format(attr_name)


@classmethod
def class_attributes(self):
return self.__class__.__dict__.keys()


if __name__ == "__main__":
object1 = MyClass(12)
object2 = MyClass(13)
print(object1.__getattr__('name'))
object1.__setattr__('name', 12)
print(object1.__getattr__('my_id'))
print(object1.__getattr__('name'))

print(object2.__delattr__('my_id'))
print(object2.__delattr__('my_id'))
print(object1.class_attributes())

0 comments on commit 0aef2c7

Please sign in to comment.