property email of Emploee object has no deleter

technical talkiess
0

 Agar apko kisis property ko delete karna hai to aap direct delete nahi kar sakte hai apko niche jaisa error milenga 


Error :- 

Printing statement is executiong....


AttributeError: property 'email' of 'Emploee' object has no deleter



Error Code :- 

class Emploee:

    def __init__(self,fname,lname):

        self.fname = fname

        self.lname = lname

        # ye property easly access hogi jaab object se call karnege

        # self.email = fname + lname +"@gmail.com"


        # ye function apko property jaise acccess karna hai to aap @property ka use kar sakte hai

        #

    @property

    def email(self):

        return f"{self.fname}.{self.lname}@vishalusrate.com"

   

    # if you want to change the any of the property of the class you can change the using of the setters method

    @email.setter

    def email(self,other):

        print("Printing statement is executiong....")

        new_data = other.split("@")[0]

        fname = new_data.split(".")[0]

        lname = new_data.split(".")[1]

        self.fname = fname

        self.lname = lname



    # creating the object of the particular class


vishal = Emploee("Vishal","Usrate")

lakhan = Emploee("lakhan","Usrate")


# print(vishal.email)


vishal.fname = "Test"

vishal.lname = "Data"

# print(vishal.email)


vishal.email = "data.tata@cent.com"


print(vishal.email)


del vishal.email




Solutiion :- 


Apko iske liye deleter bana na padenga ….. To aap isko function me jakar khali delete method ke upper apko @deleter likhna hoga uske bad property ki value ko null karna hoga ….


 Uske bad ye wala error nahi ayenga apko



Solved Code:- 


class Emploee:

    def __init__(self,fname,lname):

        self.fname = fname

        self.lname = lname

        # ye property easly access hogi jaab object se call karnege

        # self.email = fname + lname +"@gmail.com"


        # ye function apko property jaise acccess karna hai to aap @property ka use kar sakte hai

        #

    @property

    def email(self):

        if self.fname == None or self.lname == None:

            return f"Please set firsst name and last using the setter function .... email is not set yet"

        return f"{self.fname}.{self.lname}@vishalusrate.com"

   

    # if you want to change the any of the property of the class you can change the using of the setters method

    @email.setter

    def email(self,other):

        print("Printing statement is executiong....")

        new_data = other.split("@")[0]

        fname = new_data.split(".")[0]

        lname = new_data.split(".")[1]

        self.fname = fname

        self.lname = lname



    @email.deleter

    def email(self):

        self.fname = None

        self.lname = None


    # creating the object of the particular class


vishal = Emploee("Vishal","Usrate")

lakhan = Emploee("lakhan","Usrate")


# print(vishal.email)


vishal.fname = "Test"

vishal.lname = "Data"

# print(vishal.email)


vishal.email = "data.tata@cent.com"


print(vishal.fname)


del vishal.email


# vishal.email = "Test.bhai@gmail.com"

print(vishal.email)


Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)