How to convert an iterable to a stream?

前端 未结 6 1038
栀梦
栀梦 2020-11-27 18:26

If I\'ve got an iterable containing strings, is there a simple way to turn it into a stream? I want to do something like this:

def make_file():
    yield \"h         


        
6条回答
  •  一个人的身影
    2020-11-27 19:26

    TarFile takes anything that provides a file-like interface -- so you could either use StringIO (io.StringIO if you are using Python 3.X) to yield what you need to TarFile.addfile() or you could create your own class that provides a file-like interface and yields what you need.

提交回复
热议问题