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


Groups > comp.lang.python > #20158

Re: Read-only attribute in module

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mateusz@loskot.net>
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; 'subject:module': 0.04; 'defines': 0.07; 'read-only': 0.07; 'terry': 0.07; 'python': 0.08; 'context:': 0.09; 'function:': 0.09; 'api': 0.09; 'am,': 0.12; 'library': 0.13; 'bugs,': 0.16; 'nabble.com.': 0.16; 'received:192.168.236': 0.16; 'received:216.139': 0.16; 'received:216.139.236': 0.16; 'received:nabble.com': 0.16; 'reedy': 0.16; 'terry,': 0.16; 'url:nabble': 0.16; 'wrote:': 0.18; 'that?': 0.18; 'archive': 0.21; 'wrote': 0.21; 'header:In-Reply- To:1': 0.22; 'library.': 0.24; 'module': 0.26; 'import': 0.27; 'code,': 0.28; '-----': 0.28; 'language.': 0.28; 'constant': 0.29; 'module.': 0.29; 'generally': 0.30; 'semantics': 0.30; 'error': 0.30; 'list': 0.32; 'especially': 0.34; 'flag': 0.34; 'sometimes,': 0.34; 'to:addr:python-list': 0.35; 'url:python': 0.35; 'convenient': 0.37; 'charset:us-ascii': 0.37; 'received:192': 0.38; 'some': 0.38; 'should': 0.38; 'but,': 0.39; 'concepts': 0.39; 'mailing': 0.39; 'called': 0.40; 'user': 0.40; 'to:addr:python.org': 0.40; 'more': 0.61; 'view': 0.61; 'property': 0.63; 'due': 0.66; 'concept': 0.74; 'subject:Read': 0.91
Date Fri, 10 Feb 2012 03:11:52 -0800 (PST)
From mloskot <mateusz@loskot.net>
To python-list@python.org
In-Reply-To <jh161s$kqp$1@dough.gmane.org>
References <CABUeae_vv=THd0VLsAteEKu7z8U2KA4p+vK1a=nAeMSKzM-L7g@mail.gmail.com> <jh161s$kqp$1@dough.gmane.org>
Subject Re: Read-only attribute in module
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5653.1328872316.27778.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328872316 news.xs4all.nl 6987 [2001:888:2000:d::a6]:45493
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20158

Show key headers only | View raw


Terry Reedy wrote
> 
> On 2/9/2012 6:43 AM, Mateusz Loskot wrote:
>> import xyz print(xyz.flag)  # OK
>> xyz.flag = 0 # error due to no write access
> 
> Why prevent that? If you called it 'FLAG', that would indicate that it 
> is a constant that should not be changed. While Python make some effort 
> to prevent bugs, it is generally a 'consenting adults' language.
> 

Terry,

The intent of xyz.flag is that it is a value set by the module internally.
xyz is a module wrapping a C library.
The C library defines concept of a global flag set by the C functions at
some events,
so user can check value of this flag.
I can provide access to it with function: xyz.get_flag()
But, I thought it would be more convenient to have a read-only property in
scope of the module.

Sometimes, especially when wrapping C code, it is not possible to map C API
semantics to Python concepts as 1:1.

-----
-- 
Mateusz Loskot
http://mateusz.loskot.net
--
View this message in context: http://python.6.n6.nabble.com/Read-only-attribute-in-module-tp4378950p4382967.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Thread

Re: Read-only attribute in module mloskot <mateusz@loskot.net> - 2012-02-10 03:11 -0800

csiph-web