Python's "only one way to do it" philosophy isn't good?

Michele Simionato michele.simionato at
Fri Jun 29 08:23:48 CEST 2007

On Jun 29, 6:44 am, Douglas Alan <d... at> wrote:
> I've written plenty of Python code that relied on destructors to
> deallocate resources, and the code always worked.

You have been lucky:

$ cat
import logging

class C(object):
    def __init__(self):
        logging.warn('Allocating resource ...')

    def __del__(self):
        logging.warn('De-allocating resource ...')
        print 'THIS IS NEVER REACHED!'

if __name__ == '__main__':
    c = C()

$ python
WARNING:root:Allocating resource ...
Exception exceptions.AttributeError: "'NoneType' object has no
attribute 'warn'" in <bound method C.__del__ of <__main__.C object at
0xb7b9436c>> ignored

Just because your experience has been positive, you should not
dismiss the opinion who have clearly more experience than you on
the subtilities of Python.


More information about the Python-list mailing list