Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #112264

Re: make an object read only

From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: make an object read only
Date 2016-08-03 09:57 +0200
Message-ID <mailman.132.1470211075.6033.python-list@python.org> (permalink)
References <c6a0318e-af2c-4390-ab4c-a6e0fa35891a@googlegroups.com> <87mvku9te1.fsf@handshake.de>

Show all headers | View raw


Robin Becker <robin@reportlab.com> writes:

> A reportlab user found he was doing the wrong thing by calling canvas.save 
> repeatedly, our documentation says you should not use Canvas objects after the 
> save method has been used. The user had mixed results :(
>
> It would be better to make the canvas object completely immutable all the way 
> down when save has been called, but I think that's quite hard as these objects 
> have quite a large and varied set of attributes, lists other objects 
> dictionaries etc etc.

If changing things happen at an elementary level (by assigning to
the object's instance attributes), then you could implement
your on "__setattr__/__delattr__" methods. There, you could check
whether you are ready to allow the change or reject it.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

make an object read only Robin Becker <robin@reportlab.com> - 2016-08-02 08:12 -0700
  Re: make an object read only "dfh@forestfield.co.uk" <dfh@forestfield.co.uk> - 2016-08-02 09:28 -0700
  Re: make an object read only Steven D'Aprano <steve+python@pearwood.info> - 2016-08-03 02:36 +1000
  Re: make an object read only dieter <dieter@handshake.de> - 2016-08-03 09:57 +0200
  Re: make an object read only Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-04 17:03 -0700
    Re: make an object read only Robin Becker <robin@reportlab.com> - 2016-08-05 09:51 +0100
    Re: make an object read only Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-08-05 11:04 +0200
    Re: make an object read only Rick Johnson <rantingrickjohnson@gmail.com> - 2016-08-07 16:40 -0700

csiph-web