Re: Read-only attribute in module

2012-02-13 Thread mloskot
Terry Reedy wrote > > On 2/10/2012 6:11 AM, mloskot wrote: >> 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 val

Re: Read-only attribute in module

2012-02-10 Thread Terry Reedy
On 2/10/2012 6:11 AM, mloskot wrote: 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 t

Re: Read-only attribute in module

2012-02-10 Thread Steven D'Aprano
On Thu, 09 Feb 2012 22:27:50 -0500, Terry Reedy wrote: > On 2/9/2012 8:04 PM, Steven D'Aprano wrote: > >> Python happily violates "consenting adults" all over the place. We have >> properties, which can easily create read-only and write-once >> attributes. > > So propose that propery() work at m

Re: Read-only attribute in module

2012-02-10 Thread mloskot
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 effor

Re: Read-only attribute in module

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 03:27, Terry Reedy wrote: > On 2/9/2012 8:04 PM, Steven D'Aprano wrote: > >> Python happily violates "consenting adults" all over the place. We have >> properties, which can easily create read-only and write-once attributes. > > > So propose that propery() work at module level,

Re: Read-only attribute in module

2012-02-09 Thread Terry Reedy
On 2/9/2012 8:04 PM, Steven D'Aprano wrote: Python happily violates "consenting adults" all over the place. We have properties, which can easily create read-only and write-once attributes. So propose that propery() work at module level, for module attributes, as well as for class attributes.

Re: Read-only attribute in module

2012-02-09 Thread Steven D'Aprano
On Thu, 09 Feb 2012 23:32:59 +1100, Ben Finney wrote: > Mateusz Loskot writes: > >> I'm wondering, is there any mean to implement attribute in module scope >> which is read-only? > > Python is designed by and for consenting adults. Rather than > restricting, instead use conventions to make your

Re: Read-only attribute in module

2012-02-09 Thread Mark Lawrence
On 09/02/2012 11:43, 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? So, the follow

Re: Read-only attribute in module

2012-02-09 Thread Terry Reedy
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 kn

Re: Read-only attribute in module

2012-02-09 Thread mloskot
Ben Finney-10 wrote > > Mateusz Loskot writes: > >> So, the following >> >> import xyz >> print(xyz.flag) # OK >> xyz.flag = 0# error due to no write access > > PEP 8 ; gives the style > guide for Python code (strictly for the standa

Re: Read-only attribute in module

2012-02-09 Thread Ben Finney
Mateusz Loskot writes: > I'm wondering, is there any mean to implement attribute in module > scope which is read-only? Python is designed by and for consenting adults. Rather than restricting, instead use conventions to make your intent clear to the user of your library. > So, the following > >