Returning a list/dict as "read-only" from a method ?

Erik Max Francis max at alcyone.com
Thu Dec 26 21:35:49 EST 2002


Sean Ross wrote:

> This subclass of dict will allow full access, but modification is
> restricted
> to adding new key, value pairs.

The original poster mentioned copy vs. deepcopy, suggesting that the
values of his dictionary might be mutable objects.  In this case, a
subclass of dict which doesn't allow reassignments of its mapping
doesn't help.

I think the original poster is looking for something akin to const, and
unfortunately for him I think the answer is that there's no such beast
in Python.  Python takes the approach of "We're all adults here"; it
avoids the language overhead of syntax for specifying access control by
putting the burden on the part of third parties to be responsible.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ I sleep and dream that life is / All beauty
\__/ Lamya
    Official Omega page / http://www.alcyone.com/max/projects/omega/
 The official distribution page for the popular Roguelike, Omega.



More information about the Python-list mailing list