__init__ vs __new__

Daniel Klein danielkleinad at gmail.com
Thu Jan 11 15:39:39 CET 2007


I've have a program that is using both of the methods below (in
different classes of course) for initializing the class. The example
below shows a class with the 2 methods with one commented out.

class JsubroutineParameters(list):
    "Represents a list of arguments for external subroutine calls."
    # We only need to override methods which add objects to the list.

    def __init__(self, alist = []):
        for objekt in alist: _validateParameter(objekt)
        self.extend(alist)

    #def __new__(cls, alist = []):
    #    for objekt in alist: _validateParameter(objekt)
    #    return list.__new__(cls, alist)

I don't really notice any behavioral difference. Is there in fact any
difference in using one over the other? Performance? Side effects? ???

I am using Python version 2.5.

Thanks,
Daniel Klein



More information about the Python-list mailing list