del an imported Class at EOF... why?

Carl Banks pavlovevidence at gmail.com
Tue Oct 6 20:11:24 CEST 2009


On Oct 6, 10:56 am, Ryan <heni... at yahoo.com> wrote:
> Good day all!
>
> I've just inherited a large amount of python code. After spending some
> time pour through the code, I've noticed that the original developer
> (who is no longer w/ the company) constantly deletes the imported
> classes at the end of the .py file. Why would one want to do such a
> thing?


Sometimes an object is used only temporarily by a modules, while it's
importing.

In such cases, there are two reasons you might delete the object.  If
it uses a lot of memory you could free up the memory for other
objects.  Also you might want to clean up the module's namespace.

I del objects for these reasons sparingly, usually only when the
object uses a whole lot of memory, or the namespace is very messy.

However, I'm guessing that the person who wrote your code is just
overly paranoid.



Carl Banks



More information about the Python-list mailing list