shutil模块

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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • shutil -一种高层次的文件操作工具,强大之处是在对文件的复制与删除操作支持比较好。 shutil.copyf...
    翟振光阅读 1,230评论 0 0
  • 不知道从哪个阶段开始,约着下午的时间不仅仅是KTV里嗨歌了,慢慢转向聊天的方向。
    星如雨下阅读 241评论 0 1
  • 幸福的能量课 2017年6月26,27,28日,有幸参加了佐丹力(159素食)和道生平台的“幸福讲师营”。 学到三...
    周安柱阅读 839评论 0 0
  • 不是每个男人都是骑着白马的王子,所以,请不要苛求他不够高大和英俊,不要责怪他送给你的只是一双手套而不是九十九...
    秋日雏菊阅读 298评论 0 0