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


Groups > comp.lang.python > #76918 > unrolled thread

Re: why the attribute be deleted still in dir(man)?

Started byNed Batchelder <ned@nedbatchelder.com>
First post2014-08-23 20:17 -0400
Last post2014-08-23 20:17 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: why the attribute be deleted still in dir(man)? Ned Batchelder <ned@nedbatchelder.com> - 2014-08-23 20:17 -0400

#76918 — Re: why the attribute be deleted still in dir(man)?

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-08-23 20:17 -0400
SubjectRe: why the attribute be deleted still in dir(man)?
Message-ID<mailman.13369.1408839434.18130.python-list@python.org>
On 8/23/14 7:44 PM, luofeiyu wrote:
> Think for your  remark " You didn't delete the name property, which is
> part of the class, not the instance."
> I fix my codes to get the target done.
>
> class Person(object):
>         def addProperty(self, attribute):
>                getter = lambda self: self._getProperty(attribute)
>                setter = lambda self, value: self._setProperty(attribute,
> value)
>                deletter = lambda self:self.delProperty(attribute)
>                setattr(self.__class__, attribute,
> property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))
>          def _setProperty(self, attribute, value):
>                setattr(self, '_' + attribute, value.title())
>          def _getProperty(self, attribute):
>                 return getattr(self, '_' + attribute)
>          def delProperty(self,attribute):
>                 delattr(self,'_' + attribute)
>                 delattr(self.__class__, attribute)
>
> I am so happy .
>

Seriously, you should listen to the people here advising you to simplify 
this.  This is a lot of complexity to do not very much.

Why not just:

     p = Person()
     p.foo = 17

What is the point of dynamically defining properties that simply front 
attributes with a slightly different name?  Just use an attribute.

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web