Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'attribute': 0.07; 'skip:p 60': 0.07; 'subject:still': 0.09; 'def': 0.12; "'__doc__',": 0.16; 'attribute,': 0.16; 'lambda': 0.16; 'subject:)?': 0.16; '>>>': 0.22; 'header:User-Agent:1': 0.23; "skip:' 10": 0.31; '"",': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'subject:the': 0.34; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'received:10': 0.37; 'message- id:@gmail.com': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'subject: ': 0.61; "'person'": 0.84; 'subject:man': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=+Si4z+YM/0P/TmwDnJXZ5gOpP14mOUsXUa8CFpLvM40=; b=CwewmIoKsGrz2G2GzwnHqi90P/tkzPLoK5ExruMm7VhTUYAWZot4SMXwRF9tI3cYjf RrlMkrLDJcq+K9c8D7ngz7+XJme2jz0lnuOqRjeApLwBjfKBfz44nvvSBMhGFzADdx3y QOPKi6/z1qYKxiZI50RT9whO6lvKeFZyzooucD8RS0bxhYNMpuCYdg4yd86EXE69ofVG dPoqnRY0KC5fYTb14p3pyrRJtCPwHf6Hh0GRnYKfbJXMpyTAkcR3SKOcJnJ69akBWcK6 019zk/Joha1QiGfrsz++cqp/1AkCPxej/PJxSzvry9e4jEOpA9Bx+7ucUh8WBhDC1fkU HMDw== X-Received: by 10.70.88.140 with SMTP id bg12mr16444577pdb.106.1408834219647; Sat, 23 Aug 2014 15:50:19 -0700 (PDT) Date: Sun, 24 Aug 2014 06:49:53 +0800 From: luofeiyu User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: python-list@python.org Subject: why the attribute be deleted still in dir(man)? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408834228 news.xs4all.nl 2896 [2001:888:2000:d::a6]:52478 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76911 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) >>> man=Person() >>> dir(man) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__form at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__ repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref_ _', '_getProperty', '_setProperty', 'addProperty', 'delProperty'] >>> man.addProperty("name") >>> man.name="john" >>> dir(man) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__form at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__ repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref_ _', '_getProperty', '_name', '_setProperty', 'addProperty', 'delProperty', 'name '] >>> man.name 'John' >>> man.delProperty("name") >>> man.name Traceback (most recent call last): File "", line 1, in File "", line 4, in File "", line 12, in _getProperty AttributeError: 'Person' object has no attribute '_name' >>> dir(man) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__form at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__ repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref_ _', '_getProperty', '_setProperty', 'addProperty', 'delProperty', 'name']