def zapFile(filename, outfile=None):
    # outfile as zero byte? Let's throw an error and stop
    if outfile and os.path.getsize(outfile) == 0:
        raise ValueError('%s has size zero!' % outfile)

    # stat follows times to links
    original = os.stat(filename)

    # return if file already has size 0
    if original.st_size == 0:
        return None, None

    if os.path.islink(filename):
        linkdest = os.readlink(filename)
        os.unlink(filename)
        f = open(filename, "w")
        f.close()
    else:
        linkdest = None
        f = open(filename, "w")
        f.truncate()
        f.close()

    # Set original times
    os.utime(filename, (original.st_atime, original.st_mtime))
    os.chmod(filename, original.st_mode)

    return original, linkdest
replace *filename* with empty file.
dataset/ETHPy150Open CGATOxford/cgat/CGAT/IOTools.py/zapFile