python - 在 Python 中复制流

标签 python io

如何在 Python 中将流的内容传输到另一个流?

简单的解决方案是

output.write(input.read())

但如果输入文件大于可用内存(甚至无限大),则会失败;当部分副本也有用时,它也不能很好地工作。基本上我正在寻找相当于 org.apache.commons.IOUtils.copy .

最佳答案

shutil.copyfileshutil.copyfileobj 用于救援。见 http://docs.python.org/library/shutil.html#module-shutil

关于python - 在 Python 中复制流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014520/

相关文章:

Python 元类和 ModGrammar

python - Flask 301 重定向某些参数

c# - 执行File.Delete后,文件仍处于DELETE PENDING

c++ - fprintf 总是写到文件的末尾,即使我之前做 rewind(fileptr),c++

python 3 : Is the method I'm using to count the results of combination too slow?

python - pip3requirements.txt 充满垃圾

python - Django-Mongoengine : Store extra information in User Object

python - 是否可以限制 Python 中条件列表理解的长度?

c# - 异常处理问题

c - 尝试使用 C 中的 sscanf() 从文件中读取 float 、整数和字符串列表无法按预期工作