Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'tutorial': 0.03; 'c++,': 0.07; 'skip:p 60': 0.07; 'subject:still': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; '24,': 0.16; 'attribute,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'properties,': 0.16; 'subject:)?': 0.16; 'utterly': 0.16; 'wrote:': 0.18; 'trying': 0.19; "python's": 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'java': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'properties': 0.29; "doesn't": 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'subject:the': 0.34; 'classes': 0.35; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'read': 0.60; "you're": 0.61; "you'll": 0.62; "you've": 0.63; 'kind': 0.63; 'here': 0.66; 'look.': 0.84; 'subject:man': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=NWJ9vBo8+0/FMAoE++d/nQMbCWUmCjnEq8qSUOlZSRM=; b=blRZYLotlPlIX1DN5huliEvWM4+xyG59/E0ZrzKt2pWUMzhZHw92mWitCjYINqtInq F6HILi6/XzHdxnwrR85Qvoc3duledHY+hL5I8BylyG/tKZrKWQ/amHzNklj4XfbKoh3a 8aA8etFH9UDq6rGKyUb5aNj+2NPsfxqRXybn/5cyaP3p8iCq8x1tqumn6KJ7n/62laBb lVVNtVSnOykUCbaaHhGlNJyKBzr/AXnUe6z45GizWfkt0png9wWdGS13UQ/6e9CtMBzr 1IEsgK7wHzDgWcmBwiSKNy8mFXutwi6i9fD9LMumbAGM1aAjCQZ3EmgMfAr0+vUdzDGX fhZA== MIME-Version: 1.0 X-Received: by 10.50.176.202 with SMTP id ck10mr6909992igc.2.1408834616642; Sat, 23 Aug 2014 15:56:56 -0700 (PDT) In-Reply-To: <53F91A91.6080205@gmail.com> References: <53F91A91.6080205@gmail.com> Date: Sun, 24 Aug 2014 08:56:56 +1000 Subject: Re: why the attribute be deleted still in dir(man)? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408834624 news.xs4all.nl 2881 [2001:888:2000:d::a6]:57951 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76912 On Sun, Aug 24, 2014 at 8:49 AM, luofeiyu wrote: > 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) Look. Forget properties. Python is not Java or C++, and you almost never need this kind of thing. Read up a tutorial on doing classes Python's way, and you'll find that all this sort of thing just doesn't matter. You've come here with a significant number of questions about properties, and it looks as if you're trying to do everything through them - which is utterly and completely useless, especially when you use properties to be as dynamic as you're doing. Just don't do it. ChrisA