亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

詳解Python_shutil模塊

 更新時(shí)間:2019年03月15日 14:04:27   作者:Vera_y  
這篇文章主要介紹了Python_shutil模塊功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

import shutil

高級(jí)的文件,文件夾,壓縮包的處理模塊,也主要用于文件的拷貝

shutil.copyfileobj(fsrc,fdst[,length]):  將文件的內(nèi)容拷貝到另一個(gè)文件(可以指定length長(zhǎng)度進(jìn)行拷貝)

import shutil
shutil.copyfileobj(open('old.txt','r'),open('new.txt','w'))

shutil.copyfile(src,dst):  拷貝文件

import shutil
shutil.copyfile('f1.log','f2.log')

shutil.copymode(src,dst):  僅拷貝權(quán)限,內(nèi)容、組、用戶(hù)均不變

import shutil
shutil.copymode('f1.log', 'f2.log')

shutil.copystat(src,dst):  拷貝狀態(tài)的信息,包括:mode bits,atime,mtime,flags

import shutil
shutil.copystat('f1.log', 'f2.log')

shutil.copy(src,dst):  拷貝文件和權(quán)限

import shutil
shutil.copy('f1.log', 'f2.log')

shutil.copy2(src,dst):  拷貝文件和狀態(tài)信息

import shutil
shutil.copy2('f1.log', 'f2.log')

shutil.copytree(src,det,symlinks=False,ignore=None):  遞歸的去拷貝文件

import shutil
shutil.copytree('folder1', 'folder2', ignore=shutil.ignore_patterns('*.pyc', 'tmp*'))

shutil.rmtree(path[,ignore_errors[,onerror]]):  遞歸的去刪除文件

import shutil
shutil.rmtree('folder1')

shutil.move(src,dst):  遞歸的去移動(dòng)文件(重命名)

import shutil
shutil.move('folder1', 'folder3')

shutil.make_archive(base_name, format,...):  創(chuàng)建壓縮包并返回文件路徑,例如:zip、tar

base_name: 壓縮包的文件名,也可以是壓縮包的路徑。只是文件名時(shí),則保存至當(dāng)前目錄,否則保存至指定路徑(例:Presley=>保存至當(dāng)前路徑,/User/Presley =>保存至/Users/路徑下)
format: 壓縮包種類(lèi),“zip”, “tar”, “bztar”,“gztar”
root_dir: 要壓縮的文件夾路徑(默認(rèn)當(dāng)前目錄)
owner: 用戶(hù),默認(rèn)當(dāng)前用戶(hù)
group: 組,默認(rèn)當(dāng)前組

import shutil
z = shutil.make_archive('presly', 'gztar', root_dir='D:\軟件下載')

shutil對(duì)壓縮包的處理,也可調(diào)用zipfile或tarfile模塊進(jìn)行壓縮

以上所述是小編給大家介紹的Python_shutil模塊詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論