def open_as_pillow ( filename ) : with __sys_open ( filename , 'rb' ) as f : data = BytesIO ( f . read ( ) ) return Image . open ( data )
python i opened a file for writing but erased it
This way can delete file immediately
def open_as_pillow(filename):
    """ This way can delete file immediately """
    with __sys_open(filename, 'rb') as f:
        data = BytesIO(f.read())
        return Image.open(data)