james-l
4/17/2017 - 9:06 PM

python __new__ method

python new method

class Foobar(object):
    def __new__(cls, md5=None):
        if md5 is None:
            return None
        else:
            return super(Foobar, cls).__new__(cls)

    def __init__(self, md5=None):
        self.md5 = md5

def main():
    foobar = Foobar()

    if foobar is None:
        print "none"
    else:
        print foobar.md5