Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89488
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ethan@stoneleaf.us> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'init': 0.07; 'variables': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'instance.': 0.09; 'message-id:@stoneleaf.us': 0.09; 'prefix': 0.09; 'rewrite': 0.09; 'subject:hide': 0.09; 'variables.': 0.09; '~ethan~': 0.09; 'def': 0.12; 'changes': 0.15; 'length,': 0.16; 'subject:Not': 0.16; 'subject:possible': 0.16; 'valueerror,': 0.16; 'wrote:': 0.18; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'own.': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; '(maybe': 0.31; 'class': 0.32; 'quite': 0.32; 'skip:_ 10': 0.34; 'equal': 0.35; 'but': 0.35; 'done,': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'clear': 0.37; 'convention': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39; 'length': 0.61; 'received:173': 0.61; 'content-disposition:inline': 0.62; 'average': 0.93 |
| Date | Tue, 28 Apr 2015 00:56:09 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| To | python-list@python.org |
| Subject | Re: Not possible to hide local variables |
| Mail-Followup-To | python-list@python.org |
| References | <874mo0zoz2.fsf@Equus.decebal.nl> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| In-Reply-To | <874mo0zoz2.fsf@Equus.decebal.nl> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.57.1430207777.3680.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430207777 news.xs4all.nl 2829 [2001:888:2000:d::a6]:59974 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89488 |
Show key headers only | View raw
On 04/28, Cecil Westerhof wrote: > If I remember correctly you can not hide variables of a class or make > them read-only? > > I want to rewrite my moving average to python. The init is: > def __init__(self, length): > if type(length) != int: > raise ParameterError, 'Parameter has to be an int' > if n < 0: > raise ValueError, 'Parameter should be greater or equal 2' > self.length = length > self.old_values = [] > self.current_total = 0 > > But when someone changes length, old_values, or current_total that > would wreck havoc with my class instance. What is the best way to > handle this? Prefix those names with a single leading underscore, which is the convention for private variables. This way, if some user (maybe you! ;) has a good reason to change those values in can be done, but it is quite clear that said user is mucking about with internals and they are on their own. -- ~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-28 09:33 +0200
Re: Not possible to hide local variables Ethan Furman <ethan@stoneleaf.us> - 2015-04-28 00:56 -0700
Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:16 +0200
Re: Not possible to hide local variables Michael Torrie <torriem@gmail.com> - 2015-04-29 21:10 -0600
Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-28 18:06 +1000
Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:25 +0200
Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-29 17:36 +1000
Re: Not possible to hide local variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-28 18:37 +1000
Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-28 18:44 +1000
Re: Not possible to hide local variables Marko Rauhamaa <marko@pacujo.net> - 2015-04-28 12:20 +0300
Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:32 +0200
Re: Not possible to hide local variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 14:05 +1000
Re: Not possible to hide local variables Marko Rauhamaa <marko@pacujo.net> - 2015-04-30 08:10 +0300
Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-30 16:01 +1000
Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:14 +0200
Re: Not possible to hide local variables Grant Edwards <invalid@invalid.invalid> - 2015-04-29 14:16 +0000
Re: Not possible to hide local variables Dave Angel <davea@davea.name> - 2015-04-29 22:31 -0400
Re: Not possible to hide local variables Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-04-30 08:53 -0400
Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 16:50 +0200
csiph-web