python - Passing none to a property causes crashes -


i'm using properties in order get/set variables in class, when variable set none, program crashes next time variable set - in following code:

class abc(object):     def __init__(self, a=none):         self.a =      def set_a(self, value):         self._a = value*5      def get_a(self):         return self._a      = property(get_a, set_a)  = abc() a.a = 4 print a.a 

when run get:

traceback (most recent call last):   file "<string>", line 13, in <module>   file "<string>", line 3, in __init__   file "<string>", line 6, in set_a typeerror: unsupported operand type(s) *: 'nonetype' , 'int' 

what's correct way of writing code stop error occurring?

set self._a, not self.a; latter uses property setter:

class abc(object):     def __init__(self, a=none):         self._a = 

or use numeric default instead:

class abc(object):     def __init__(self, a=0):         self.a = 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -