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


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

Re: Read-only attribute in module

Started byTerry Reedy <tjreedy@udel.edu>
First post2012-02-09 14:15 -0500
Last post2012-02-09 14:15 -0500
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 Terry Reedy <tjreedy@udel.edu> - 2012-02-09 14:15 -0500

#20097 — Re: Read-only attribute in module

FromTerry Reedy <tjreedy@udel.edu>
Date2012-02-09 14:15 -0500
SubjectRe: Read-only attribute in module
Message-ID<mailman.5604.1328814988.27778.python-list@python.org>
On 2/9/2012 6:43 AM, Mateusz Loskot wrote:
> Hi,
>
> I'm implementing Python 3 extension using the Python C API. I am
> familiar with defining new types, implementing get/set for
> attributes, etc.
>
> I'm wondering, is there any mean to implement attribute in module
> scope which is read-only?

Not that I know of. Python intentionally leaves modules mutable even 
after the code has executed so they can be monkey-patched from outside. 
The argument for is that it is unusual to do so but sometimes very 
useful and necessary. The main argument against is that it prevents 
optimizations that would make code in modules run faster.

> 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 Jan Reedy

[toc] | [standalone]


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


csiph-web