locking dictionaries (was Re: New statement proposal for Python)

Michael Hudson mwh at python.net
Thu Jun 21 18:23:41 EDT 2001


Greg Ewing <see at my.signature> writes:

> Hmmm... wild thought: after type/class healing,
> every object will have a __class__ attribute...
> if it were changeable...
> 
>   d = {'spam':42}
>   d.__class__ = MyLockedDictClass
> 
> No, probably far too dangerous...
> 
>   x = []
>   x.__class__ = 3.__class__
>   print x
> 
> <<<fireworks as python interpreter self-destructs>>>

On descr-branch:

>>> [].__class__
<type 'list'>
>>> [].__class__ = type(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: readonly attribute

Assigning to (3).__class__ or "a".__class__ would actually be much
more insidious...

Cheers,
M.

-- 
  This makes it possible to pass complex object hierarchies to
  a C coder who thinks computer science has made no worthwhile
  advancements since the invention of the pointer.
                                       -- Gordon McMillan, 30 Jul 1998



More information about the Python-list mailing list