Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'class,': 0.07; 'attributes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rewrite': 0.09; 'def': 0.12; 'windows': 0.15; '"python': 0.16; '>in': 0.16; 'class)': 0.16; 'message- id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Classes': 0.16; 'version"': 0.16; 'print': 0.22; 'url:home': 0.24; 'class.': 0.26; 'header:X-Complaints-To:1': 0.27; '(c)': 0.29; '2009': 0.29; 'properties': 0.29; 'code': 0.31; 'class': 0.32; 'skip:c 30': 0.32; 'fri,': 0.33; 'skip:_ 10': 0.34; 'definition': 0.35; 'objects': 0.35; 'but': 0.35; 'version': 0.36; 'accessing': 0.36; 'charset:us-ascii': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'conversion': 0.61; 'first': 0.61; 'organization': 0.63; 'direct': 0.67; 'reserved.': 0.68; 'received:108': 0.93; 'taught': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Classes Date: Fri, 31 Oct 2014 18:26:02 -0400 Organization: IISS Elusive Unicorn References: <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> <545350c3$0$23449$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-221-33.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414794369 news.xs4all.nl 2860 [2001:888:2000:d::a6]:50067 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80064 On Fri, 31 Oct 2014 12:31:56 -0400, Seymore4Head declaimed the following: > >In this class, we will follow the practice of accessing the contents >of objects using methods known as getters and setters. While not >required by Python, this practice encourages the user of the class to >manipulates class objects solely via class methods. The advantage of >following this practice is that the implementer of the class >definition (often someone other than the user of the class) may >restructure the organization of the data fields associated with the >object while avoiding the need to rewrite code that uses the class. In Python, the conversion of direct attributes into properties does exactly that -- NO REWRITE of using code... What you are being taught is NOT PYTHON. -=-=-=-=-=-=- def user(): mySomething = Something() print mySomething.who print id(mySomething), id(Something) print mySomething.X mySomething.X = 123 print mySomething.X print "********" class Something(object): def __init__(self): self.X = None self.who = "I am the direct access version" user() #invoke a user with first class definition #now redefine the class with properties class Something(object): def __init__(self): self._X = None self.who = "I am the property version with getter/setter" def _setX(self, vlu): self._X = vlu def _getX(self): return self._X X = property(_getX, _setX) user() #invoke the SAME USER CODE but with class now using properties -=-=-=-=-=-=- Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Wulfraed\Documents>cd "Python Progs" C:\Users\Wulfraed\Documents\Python Progs>property.py I am the direct access version 35663488 35817816 None 123 ******** I am the property version with getter/setter 35663488 35818760 None 123 ******** C:\Users\Wulfraed\Documents\Python Progs> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/