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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'example:': 0.03; 'attribute': 0.07; 'permitted': 0.07; 'python': 0.11; 'def': 0.12; 'name):': 0.16; 'subject:between': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'initial': 0.24; 'header:In-Reply- To:1': 0.27; 'to:2**1': 0.27; '"",': 0.31; 'depth': 0.31; 'subject:what': 0.31; 'file': 0.32; 'class': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'classes': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; '(3)': 0.38; 'to:addr:python-list': 0.38; 'use.': 0.39; 'to:addr:python.org': 0.39; 'name': 0.63; 'maximum': 0.63; 'charset:windows-1252': 0.65; 'exceeded': 0.97 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:content-transfer-encoding; bh=DwmAInbNiBtzU8UImIuCAbTrfIsHFu0kM1L7PHefY0E=; b=AUML0BGX4V+i+cElPa/ucl5i+FoMGZ3e3EzcmerO8tBR17wEd8XXoYQj0XBXm4O8hX YgAE+Acx1smq7xPIGzDS3Fgez2HTQjMz0/xTcbAp25Re9DIitXBX6vyMUyRv7xYqE5Mw /IjdK511ePFbo262iihYf/7xpLfY5ubjB1WmcFI/t7AunR66164m53Uv2RTjEoDXFwQc SzVyGy0sz6kVvLQ56AmWOC/SJQZIsX0cFO6wPc8zIwd3qy//B3/UeArw8ehNK8sxvRwe hb7WaRgWuR4mWcSrDcAxMoCv8FJ+Gaw3uBmE37kP25EcewIZo5TiSFjkoG7RcxxS5v6p qPJw== X-Received: by 10.66.66.193 with SMTP id h1mr48116033pat.93.1408534895770; Wed, 20 Aug 2014 04:41:35 -0700 (PDT) Date: Wed, 20 Aug 2014 19:41:11 +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: Steven D'Aprano , python-list@python.org Subject: Re: what is the difference between name and _name? References: <53f46100$0$29884$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <53f46100$0$29884$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=windows-1252; 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: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408534898 news.xs4all.nl 2901 [2001:888:2000:d::a6]:45925 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76657 So in this example: >> class Person(object): >> def __init__(self, name): >> self._name = name > [...] >> name = property(getName, setName, delName, "name property docs") > > > (3) name is the public attribute that other classes or functions are > permitted to use. > > > problem 1: there is no self.name = something in the defination ,why i can get bob.name? > > class Person(object): def __init__(self, name): self._name = name def getName(self): print('fetch....') return self._name def setName(self, value): print('change...') self._name = value def delName(self): print('remove....') del self._name name = property(getName, setName, delName, "name property docs") >>> bob=Person("dear bob") >>> bob._name # there is a defination in class Person ,self._name = name ,when we initial it ,we can get bob._name 'dear bob' >>> bob.name #there is no defination in class Person ,self.name=name ,why we can get the value of bob.name? fetch.... 'dear bob' problem 2: what is the meaning of name = property(getName, setName, delName, "name property docs") ? why i can not write _name = property(getName, setName, delName, "name property docs") ? class Person(object): def __init__(self, name): self._name = name def getName(self): print('fetch....') return self._name def setName(self, value): print('change...') self._name = value def delName(self): print('remove....') del self._name _name = property(getName, setName, delName, "name property docs") bob=Person("dear bob") I got error from the codes: File "", line 9, in setName File "", line 8, in setName RuntimeError: maximum recursion depth exceeded while calling a Python object