[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python3 - How do I import a class from another file

On Tue, Dec 10, 2019 at 9:51 PM R.Wieser <address at 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

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