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


Groups > comp.lang.python > #20158 > unrolled thread

Re: Read-only attribute in module

Started bymloskot <mateusz@loskot.net>
First post2012-02-10 03:11 -0800
Last post2012-02-10 03:11 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#20158 — Re: Read-only attribute in module

Frommloskot <mateusz@loskot.net>
Date2012-02-10 03:11 -0800
SubjectRe: Read-only attribute in module
Message-ID<mailman.5653.1328872316.27778.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web