Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'class,': 0.07; 'decorator': 0.09; 'function,': 0.09; 'rewrite': 0.09; 'python': 0.11; 'def': 0.12; 'attribute,': 0.16; 'attribute.': 0.16; 'class)': 0.16; 'complicated,': 0.16; 'fetches': 0.16; 'parentheses': 0.16; 'subject:Classes': 0.16; 'wrote:': 0.18; 'written,': 0.19; 'written': 0.21; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'change,': 0.30; 'needed.': 0.30; 'code': 0.31; 'equivalent.': 0.31; 'class': 0.32; 'regular': 0.32; 'updated': 0.34; 'skip:_ 10': 0.34; 'definition': 0.35; 'done.': 0.35; 'objects': 0.35; 'but': 0.35; 'accessing': 0.36; 'should': 0.36; 'members.': 0.37; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'organization': 0.63; 'more': 0.64; 'details': 0.65; 'here': 0.66; 'received:74.208': 0.68; 'price': 0.69; 'age': 0.80; '"just': 0.84; 'decorate': 0.84; 'received:74.208.4.194': 0.84 Date: Fri, 31 Oct 2014 13:20:36 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Classes References: <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> <545350c3$0$23449$426a74cc@news.free.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:WfXpLYyYruk4UpZHteZ1uYeO8vMqZDcDs0jwGU4WJa0 Ttg7rPlPrmH69RhTfZCqoQ2ARlVxTglw0GOhlcpwZgwIuiF9Sa JUMAy3WhQ6lEdFNa0Af7mSBS49GXJoqhJFoMzVbi3jESd7i4OS HTX9sfrInJ15P49eTmsPpqEDE/3QNkO10OB0VG9BAn+uYjU5jd 3v9IE85fkzJhA8imvv5yfzPS7gCcZ78f6ct2wHkZuxD0thEpqo aURwIy7djdxcqJAIGXYrv4zZvHU7AR5WhQmr0y39EOHztel8zi w1kP9jZRqNSeEHp8ldP863bxL9YAmmxYAw88ULuvuJzCYRhwOK rHrVARNCjYdw/Ghka6QM= X-UI-Out-Filterresults: notjunk:1; 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414776040 news.xs4all.nl 2935 [2001:888:2000:d::a6]:48306 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80032 On 10/31/2014 12:31 PM, Seymore4Head wrote: > 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. > Written by somebody who doesn't understand a fundamental point about Python. It's just not true that the user would have to rewrite code if the implementer change the members. The Python way of writing getters and setters (if/when you get to that stage of a Python class) is through the property decorator or its equivalent. class Pet(): def __init__(self, ....): self.internal details set here @property() def age(self): return some_complicated_expression And the user of the class fetches this by using mypet = Pet(....) hisage = mypet.age No stupid parentheses needed. When the class is first written, no work is needed. When it's updated to multiply the internal age by 7, just write the function, and decorate it to look like a regular attribute. More complicated things can be done. But the point is that the user should just get the age, by accessing the age attribute, and if the implementation needs to change, it can change. The time to make a class complicated, is when it needs to be. And the user should not have to pay the price for "just in case." -- DaveA