On Tue, Dec 10, 2019 at 9:51 PM R.Wieser <address@not.available> wrote:
>
> Greg,
>
> > In that case, it was only working by accident.
>
> I don't think so.
>
> Or you must be thinking that the __del__ method of an instance is only
> called by the garbage collector - which would be rather daft (just think of
> a file thats created when initialising an instance, but not closes until the
> garbage collector comes around to it.   Much luck with reopening the file).
> Removing an unused object from memory is a bit different than
> closing/"destroying" an instance.

Well, that's exactly what happens. Daft as it might seem, the __del__
method IS only called when an object is disposed of by the garbage
collector. CPython happens to use a refcounting garbage collector that
will usually dispose of things fairly promptly, but in the case of
cyclic references, that won't happen till the cycle detection GC goes
through.

Check out the 'with' statement. Also, when you scorn something without
knowing your facts, you tend to make yourself look like a fool :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to