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 standard library, but it is
> recommended for all Python code).
> 

Ben,

That's what I thought really.
Thank you for confirming the sanity of the style-powered conventions.

Best regards,

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


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 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.
-- 
http://mail.python.org/mailman/listinfo/python-list


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 value of this flag.
>> I can provide access to it with function: xyz.get_flag()
> 
> If the value of the flag can change during a run, I would do that. 
> Otherwise, you have to make sure the local copy keeps in sync. Users 
> might also think that it is a true constant that they could read once.
> 
> I understand that you might be concerned that one person in a 
> multi-programmer project might decide to rebind xyz.flag and mess up 
> everyone else. I think the real solution might be an option to freeze an 
> entire module.
> 

Terry,

Thanks for your really helpful notes.

Best regards,


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


Re: How do I tell "incomplete input" from "invalid input"?

2012-01-11 Thread mloskot

Terry Reedy wrote
> 
> On 1/11/2012 8:50 AM, Mateusz Loskot wrote:
>> Unfortunately, this FAQ is either old or incomplete thus incorrect.
> 
> If you have a suggested change to the current text, please submit it to 
> the tracker at bugs.python.org
> 

Yes, this is quite obvious procedure to me, but first I wanted to discuss
the problem
and to try to find proper solution worth to be included in the FAQ.

Best regards,

-
-- 
Mateusz Loskot
http://mateusz.loskot.net
--
View this message in context: 
http://python.6.n6.nabble.com/How-do-I-tell-incomplete-input-from-invalid-input-tp3585241p3632798.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list