Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20097 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2012-02-09 14:15 -0500 |
| Last post | 2012-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.
Re: Read-only attribute in module Terry Reedy <tjreedy@udel.edu> - 2012-02-09 14:15 -0500
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-02-09 14:15 -0500 |
| Subject | Re: 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
Back to top | Article view | comp.lang.python
csiph-web