[Tutor] maximum recursion error

monikajg at netzero.net monikajg at netzero.net
Thu Sep 15 22:36:26 EDT 2016


Hi:
Below is code where mistakenly self.var is named the same as function var instead of a different name. I know that this is not correct but I was experimenting to see what happens.
class GetSet():

    def __init__(self, value):
        #self.attrval = value
        self.var = value

    @property
    def var(self):
        print "getting the var attribute. "
        #return self.attrval
        return self.var
    @var.setter 
    def var(self,value):
        print "setting the var attribute"
        #self.attrval = value
        self.var = value

    @var.deleter
    def var(self):
        print "deleting the var attribute. "
        #self.attrval = None
        self.var = None

When I run the code with below I get " maximum recursion depth exceeded while calling a Python object" which is what I expected.
me = GetSet(5)
me.var = 1000
print me.var   - I do not get "max recursion error" here. Why?
del me.var
print me.var   - Here I get "max recursion error"

What I do not understand is why I do not get the same error when runing below:

me = GetSet(5)
me.var = 1000
print me.var

Why do I get the error after I do del but not without del? Why do I get the error after doing print me.var for the second time but not for the first time? In my understanding I should get the recursion error after the first print me.var.
Why do I have to del and print again me.var to get the "max recursion error"?
Thank you very much
Monika



____________________________________________________________
Do This Before Bed Tonight to Burn Belly Flab All Night Long
Flat Belly Overnight
http://thirdpartyoffers.netzero.net/TGL3241/57db5afb836b65afb35f7st04duc


More information about the Tutor mailing list