Object Introspection

 # Types to inspect an object are :

# type(object)

# id(object)

# Next 2 line are on function only !!
# o = MyClass()
# print(dir(o))

# Main Code:


class Employee:
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
# self.email = f"{fname}.{lname}@codewithharry.com"

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

@property
def email(self):
if self.fname==None or self.lname == None:
return "Email is not set. Please set it using setter"
return f"{self.fname}.{self.lname}@codewithharry.com"

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

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


skillf = Employee("Skill", "F")
# print(skillf.email)
o = "this is a string"
# print(dir(skillf))
# print(id("that that"))

import inspect
print(dir(skillf))
print(inspect.getmembers(skillf))

Comments

Popular posts from this blog

Practice Execise 3

Pickle Module