Does Python really follow its philosophy of "Readability counts"?
steven at REMOVE.THIS.cybersource.com.au
Thu Jan 22 08:59:57 CET 2009
On Wed, 21 Jan 2009 01:02:37 -0800, Aaron Brady wrote:
>> >>> class Parrot:
>> ... _private = 'spam'
>> ...>>> p = Parrot()
>> >>> p._private = 'ham' # allowed by default from protection import
>> >>> lock
>> >>> lock(p)._private
>> >>> p._private = 'spam'
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> ProtectionError: attribute is read-only from outside of class Parrot
>> Would that be so bad? I don't think so.
> Sorry, I didn't see the last part originally. I don't think 'outside of
> class Parrot' is well-defined in Python. Does '_private' have to be a
> member of 'Parrot', an instance of 'Parrot', or the calling instance of
> 'Parrot', before entering the calling scope, or at the time the call is
> made? Since many of these can change on the fly, there's more than one
> consistent interpretation to the syntax.
This is a good point. Any hypothetical move to make Python (or a Python-
like language) stricter about private/protected attributes would need to
deal with that question. I don't have to worry about that until somebody
writes a PEP :)
More information about the Python-list