Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104546

Re: Encapsulation in Python

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Newsgroups comp.lang.python
Subject Re: Encapsulation in Python
Date Thu, 10 Mar 2016 19:35:14 +0000
Lines 34
Message-ID <mailman.150.1457638586.15725.python-list@python.org> (permalink)
References <56E17985.7060002@benmezger.nl> <633796af251848feba7b6eed5e72e25a@seaexchmbx03.olympus.F5Net.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de mOn7UYmxGCyqjnBdUstiLgjrsmP4+XxgiWiPEMd7YF9g==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'attributes': 0.07; 'name):': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'java,': 0.15; 'attribute;': 0.16; 'attributes,': 0.16; 'java.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'language': 0.19; 'lawrence': 0.22; 'oriented': 0.22; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'dan': 0.29; 'sure,': 0.29; 'skip:_ 10': 0.32; 'language.': 0.32; 'point': 0.33; 'class': 0.33; 'foo': 0.33; 'int': 0.33; "i'll": 0.33; 'except': 0.34; 'gives': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'doing': 0.38; 'itself': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'skip:n 10': 0.62; 'our': 0.64; 'benefit': 0.66; 'python-list': 0.66; 'age': 0.84; 'pythonistas,': 0.84; 'studying': 0.84; 'why?': 0.91; 'subject:skip:E 10': 0.96
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 80.234.129.0
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
In-Reply-To <633796af251848feba7b6eed5e72e25a@seaexchmbx03.olympus.F5Net.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
Xref csiph.com comp.lang.python:104546

Show key headers only | View raw


On 10/03/2016 14:57, Dan Strohl via Python-list wrote:
>> I've been studying Object Oriented Theory using Java. Theoretically, all
>> attributes should be private, meaning no one except the methods itself can
>> access the attribute;
>>
>> public class Foo {
>>      private int bar;
>>      ...
>

For the benefit of any newbies/lurkers I'll just point out that this 
might well be valid Java, but...

> Why?  I mean sure, lots of them should be, but if I am doing something like:
>
> class person:
>       age = 21
>       name = 'Cool Dude'
>

...this gives you class attributes, so the age is always 21 and the name 
is always 'Cool Dude'.  So you can vary the age and name you'd need:-

class person():
     def __init__(self, age, name):
         self.age = age
         self.name = name

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-10 19:35 +0000
  Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 15:52 -0800
  Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 17:12 -0800

csiph-web