Get MD5 checksum hash of big files in Python

def checkHash(filename, blocksize=2**20):

    try:

        print(“need to creating hash of file ” +filename)

        m = hashlib.md5()

        with open(filename , “rb” ) as f:

            while True:

                buf = f.read(blocksize)

                if not buf:

                    break

                m.update( buf )

        hash1=m.hexdigest()

        print(“hash of above file is  ” + hash1)

        return hash1

    except :

        print(“Exception in hash code:”)

        print(“-” * 60)

        traceback.print_exc(file=sys.stdout)

        print(“-” * 60)

        return “error”