Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76917
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <elearn2014@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.032 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'attribute': 0.07; 'class,': 0.07; 'skip:p 60': 0.07; 'instance.': 0.09; 'subject:still': 0.09; 'def': 0.12; "'__doc__',": 0.16; 'attribute,': 0.16; 'lambda': 0.16; 'storing': 0.16; 'subject:)?': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'fix': 0.17; '>>>': 0.22; 'header:User-Agent:1': 0.23; '>>>': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; "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; 'done.': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'skip:& 10': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; '12,': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; "you're": 0.61; 'name': 0.63; 'to:2**2': 0.65; 'to:addr:gmail.com': 0.65; 'charset:windows-1252': 0.65; '8bit%:100': 0.72; "'person'": 0.84; 'remark': 0.84; 'subject:man': 0.84; '8bit%:18': 0.93 |
| 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:references :in-reply-to:content-type; bh=KEO3TDXfV7vhXjQrLtL3et4Mu6LIdv90mLaWXX7o1ow=; b=JeI526xDZH6yurMH9E82HITLl37r8j5OZSpwMU0D1e9iAjsJndDF4RapbSHQSDBEXR n9BHfPXSXGGI/neRsVyQrBJOpZfqU8Kh0XA8wMbHFMPzbSGpe2TwTdJomfq2m3NhdzZZ 31SUfK1kD/S+7E7rwm3iRT2I6qWMeWOsx1VrvgtfsDfYNU6SQEldSgdI8BKpXs9tHw6B 4MY8OTtdnziMHkEoKqfboSGSD7R7N55ateuNGZOoRzQ079YgTIiB/G9MFfCAi5YXe1sW eF6Enl0PkGqOVx/g6IOPJ8/UG+GoLf9RYt/B8E+W0fVBDMA29y/DfCsIQOK6ORddmWhF YbHg== |
| X-Received | by 10.68.106.194 with SMTP id gw2mr16555484pbb.85.1408837508344; Sat, 23 Aug 2014 16:45:08 -0700 (PDT) |
| Date | Sun, 24 Aug 2014 07:44:47 +0800 |
| From | luofeiyu <elearn2014@gmail.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
| MIME-Version | 1.0 |
| To | Ian Kelly <ian.g.kelly@gmail.com>, Chris Angelico <rosuav@gmail.com>, python-list@python.org |
| Subject | Re: why the attribute be deleted still in dir(man)? |
| References | <53F91A91.6080205@gmail.com> <CALwzidnb2MpyiXCUftbHZLkBWbMYBKbWHZFQMS0vYnxH6NbXOw@mail.gmail.com> |
| In-Reply-To | <CALwzidnb2MpyiXCUftbHZLkBWbMYBKbWHZFQMS0vYnxH6NbXOw@mail.gmail.com> |
| Content-Type | multipart/alternative; boundary="------------000808070902020404080103" |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13368.1408837517.18130.python-list@python.org> (permalink) |
| Lines | 128 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1408837517 news.xs4all.nl 2913 [2001:888:2000:d::a6]:46658 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:76917 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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 .
>
> > >>> man.delProperty("name")
> > >>> man.name <http://man.name>
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > File "<stdin>", line 4, in <lambda>
> > File "<stdin>", 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']
>
> You deleted the _name attribute where you're storing the value of the
> name property. You didn't delete the name property, which is part of
> the class, not the instance.
>
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: why the attribute be deleted still in dir(man)? luofeiyu <elearn2014@gmail.com> - 2014-08-24 07:44 +0800
csiph-web