shutil -一種高層次的文件操作工具,強大之處是在對文件的復制與刪除操作支持比較好。
在代碼中用到copyfileobj(),主要是將url返回的數據復制到jpg文件中,形成一個圖形
if result.status_code == 200:
#將圖片數據copy
with open(filename,'wb') as f:
result.raw.decode_content = True
shutil.copyfileobj(result.raw,f)```
1. `copyfileobj(fsrc,fdst[,length]]`
copy the contents of the file-like object fsrc to the file-like object fdst. The integer length, if given, is the buffer size.
2. `copyfile(src,dat)`
從源src復制到dst中,前提是目標地址具有可寫權限。
3. `copymode(src,dst)`
copy the permission bits from src to dst.只會復制權限,其他東西并不會復制
4. `copystat(src,dst)`
copy the permission bits,last access time, and last modification time from src to dst.
5. `copy(src,dst)`
copy the file src to the file or directory dst.
6. `copy2(src,dst)`
similar to copy(), but last access time and last modification time are copied as well. cp -p
6. `copytree(olddir,newdir,True/False)`
如果是Truename將保持文件夾下的符號鏈接
7. `rmtree(path)`
delete an entire directory tree, path must point to a directory
8. `move(src,dst)`
move a file or directory to another location.