Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76738
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.057 |
| X-Spam-Evidence | '*H*': 0.89; '*S*': 0.00; 'attribute': 0.07; 'val': 0.09; 'def': 0.12; 'self.y': 0.16; 'subject: \n ': 0.16; 'subject:make': 0.16; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'replace': 0.24; 'correct': 0.29; 'initiate': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'maybe': 0.34; 'subject:from': 0.34; 'received:google.com': 0.35; 'there': 0.35; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'subject: ': 0.61; 'between': 0.67; 'exam': 0.84; 'x):': 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=atpQl+Tejw9Dygj9JK7rrcFvJBSdWdBrzht1zMLuJQA=; b=IBK7CaiM7+a+t2ofxGzL7yTrGwYM34fyh7TIZz6sukQ7bvvQu6mghSLArUae1XCJ+j 0c5Nys++Ap6IIlU7lrKhE2M+I4W9hN2nGp0ui00P1gHnqlyidyW5spCAFhoy38QBvTen /m48xIFZ3xt+qOcO14zpUYRQKvTdzkGiG5GPZZ0Ok9PZWDWm93tb0JY7G2Z3loy+eCgv BSBJWgipO+YqhZ5zy9bcIZLyxneBRM1JszkWeLqLU4ZEYVdyD4PZYgs5f/sPDPwS0BIV MGzrHfLB7iSTPX8nPtukIcVISWPdlbH5t5krCgbSDFGwF/V7PGwWAsj1x9e931sK0WRx 42+Q== |
| X-Received | by 10.68.229.166 with SMTP id sr6mr61634887pbc.33.1408630429125; Thu, 21 Aug 2014 07:13:49 -0700 (PDT) |
| Date | Thu, 21 Aug 2014 22:13:32 +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 | python-list@python.org |
| Subject | Distinguishing attribute name from varible name to make codes clear and definite |
| 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 <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.13252.1408630431.18130.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1408630431 news.xs4all.nl 2887 [2001:888:2000:d::a6]:42516 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:76738 |
Show key headers only | View raw
I feel that self.x and x will be confused in the following codes.
class MyDescriptor(object):
def __init__(self, x):
self.x = x
def __get__(self, instance, owner):
print('get from descriptor')
return self.x
def __set__(self, instance, value):
print('set from descriptor')
self.x = value
def __delete__(self, instance):
print('del from descriptor, the val is', self.x)
exam=MyDescriptor("hallo")
when class MyDescriptor initiate , the `hallo` was passed into x in
__init__(self, x);
Literally self.x maybe understood to be self.hallo ,assign a attribute
named 'hallo' to instance exam.
It is a better way to replace self.x to self.y .
class MyDescriptor(object):
def __init__(self, x):
self.y = x
def __get__(self, instance, owner):
print('get from descriptor')
return self.y
def __set__(self, instance, value):
print('set from descriptor')
self.y = value
def __delete__(self, instance):
print('del from descriptor, the val is', self.y)
exam=MyDescriptor("hallo")
There is a attribute y in instance exam , the `hallo` was passed into x
in __init__(self, x).No any relation between x and y ,`hallo` and y.
My view is correct or not ?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Distinguishing attribute name from varible name to make codes clear and definite luofeiyu <elearn2014@gmail.com> - 2014-08-21 22:13 +0800 Re: Distinguishing attribute name from varible name to make codes clear and definite Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-21 14:23 +0000
csiph-web