Python complaints

alex alex at somewhere.around.here
Wed Nov 24 21:33:39 EST 1999


> suppose you have a piece of code that builds a big data structure out
> of class instances; then every time you make a small change and run it
> again (you have to run it again, because existing instances belong to
> the old versions of the classes) you can be leaking a lot of memory.

Sometimes you don't have to run the whole thing again.  E.g.

>>> class A: 
...   def __init__(self,data):self.data=data
... 
>>> t=A(5)
>>> t
<__main__.A instance at 815d370>
>>> class A:
...   def __repr__(self):return "This really is the new version"
... 
>>> t.__class__=A
>>> t
This really is the new version
>>> t.data
5
>>> 

This can be very useful if you want to fiddle with a method in an object
that takes a long time to initialize.  

But you're probably right about the memory management.

Alex.




More information about the Python-list mailing list