Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66841

property confusion

From K Richard Pixley <rich@noir.com>
Newsgroups comp.lang.python
Subject property confusion
Message-ID <OkNNu.57622$m75.43166@fx07.iad> (permalink)
Date 2014-02-21 10:58 -0800

Show all headers | View raw


Could someone please explain to me why the two values at the bottom of 
this example are different?

Python-3.3 if it makes any difference.

Is this a difference in evaluation between a class attribute and an 
instance attribute?

--rich

class C:
     def __init__(self):
         self._x = None

     def getx(self):
         print('getx')
         return self._x
     def setx(self, value):
         print('setx')
         self._x = value
     def delx(self):
         print('delx')
         del self._x
     x = property(getx, setx, delx, "I'm the 'x' property.")

class D:
     def getx(self):
         print('getx')
         return self._x
     def setx(self, value):
         print('setx')
         self._x = value
     def delx(self):
         print('delx')
         del self._x

     def __init__(self):
         self._x = None
         self.x = property(self.getx, self.setx, self.delx, "I'm the 'x' 
property.")

type(C().x)
type(D().x)

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

property confusion K Richard Pixley <rich@noir.com> - 2014-02-21 10:58 -0800
  Re: property confusion Rotwang <sg552@hotmail.co.uk> - 2014-02-21 19:33 +0000

csiph-web