1 2 3 4 5
# construct a bytes object from a generator def gen(): for i in range(4): yield i print(bytes(gen()))