why*_*why 4 python file-io file
我可以用红宝石
File.open('yyy.mp4', 'w') { |f| f.write(File.read('xxx.mp4')}
Run Code Online (Sandbox Code Playgroud)
我可以使用Python吗?
Mar*_*ers 18
你当然可以:
with open('yyy.mp4', 'wb') as f:
f.write(open('xxx.mp4', 'rb').read())
Run Code Online (Sandbox Code Playgroud)
注意二进制模式标志there(b),因为你要复制mp4内容,你不希望python为你重新解释换行符.
如果很大,这将占用大量内存xxx.mp4.看一下该shutil.copyfile函数,以获得更节省内存的选项:
import shutil
shutil.copyfile('xxx.mp4', 'yyy.mp4')
Run Code Online (Sandbox Code Playgroud)