def read(self, buf, n):
        l = min(len(self.prev), n)
        buf[:l] = self.prev[:l]
        self.prev = self.prev[l:]  # pitfall self.prev = []

        idx = l  # the next reading
        while idx < n:
            buf4 = ["" for _ in xrange(4)]
            r = read4(buf4)
            if idx+r < n:
                buf[idx:idx+r] = buf4[:r]
                idx += r
                if r < 4: return idx
            else:
                buf[idx:n] = buf4[:n-idx]
                self.prev = buf4[n-idx:r]  # pitfall buf4[n-idx:]
                idx = n

        return idx
read n chars to buf, called multiple times
dataset/ETHPy150Open algorhythms/LeetCode/158 Read N Characters Given Read4 II - Call multiple times.py/Solution.read