Object Introspection in python

 class Employee:

    def __init__(selffnamelname):
        self.fname = fname
        self.lname = lname
        # self.email = f"{fname}{lname}@gmail.com"

    def explain(self):
        return f"This employee is {self.fname} {self.lname} and the email is {self.email}"

    @property  # Decorator....
    def email(self):
        if self.fname == None or self.lname == None:
            return "Email not set please set email with setter"
        return f"{self.fname}{self.lname}@gmail.com"

    @email.setter
    def email(selfstring):
        print("Setting now...")
        split = string.split("@")[0]
        a = split.split(".")
        self.lname = a[1]
        self.fname = a[0]

    @email.deleter
    def email(self):
        self.fname = None
        self.lname = None


skillf = Employee("Umair""Developer")
# methods of object introspection
# print(type(skillf))
# print(id("this is a "))
# print(dir(skillf))

import inspect
print(inspect.getmembers(skillf))
 

Comments