美文网首页
shutil模块

shutil模块

作者: KevinCool | 来源:发表于2016-06-08 17:09 被阅读1142次

    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模块

          本文链接:https://www.haomeiwen.com/subject/npujdttx.html