osdir.com


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

Python3 - How do I import a class from another file


On 10/12/19 9:45 pm, R.Wieser wrote:

> In my case deleting the instance was needed to release its hold on something
> that was taken when the instance was initialised (in my case a GPIO pin on a
> Raspberry Pi).   I did not even think of garbage collection.

In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared. That happens to be
true currently in CPython (which uses reference counting), but it's
not guaranteed by the language.

If your object has a method for explicitly making it release its
resources, it would be better to use that rather than rely on
the garbage collector.

> Than again, I normally camel-case my variable and function names (to make
> them stand out from the build-in commands), as I normally do not use editors
> with syntax highlighting.

Python differs from VBScript and other VB-family languages in that
names are case-sensitive. So it's common to use case to distinguish
between things such as a class and an instance.

-- 
Greg