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

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


On Jun 29, 6:44 am, Douglas Alan <d... at alum.mit.edu> 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 deallocating.py
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 deallocating.py
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.

                 Michele




More information about the Python-list mailing list