Python工具
1. argparse
import argparse
parser = argparse.ArgumentParser(description="descriptions")
parser.add_argument('--angle',type=int,default=0)
parser.add_argument('--choose',action='store_true',defalut=False)
args = parser.parse_args()
2. tqdm
pip install tqdm
from tqdm import *
pBar = tqdm(total=1000)
for i in range(1000):
pBar.update(1)
3. os, shutil
判断是否是文件夹:os.path.isdir(path)
判断是否为文件: os.path.isfile(path)
判断文件是否存在: os.path.exists()
分离目录和文件:dir,file = os.path.split(path)
or dir = os.path.dirname(path)
or file = os.path.basename(path)
循环中列出路径: os.listdir(path)
创建文件:touch -> f = open('./test.txt','w')
递归移动目录 move: shutil.move(src,dst)
rename: os.rename(old,new)
创建多级目录:os.mkdirs(path)
copy: shutil.copy(from,to)
获取当前命令:os.getcwd()
remove: os.remove(path)
os.remove(path)
#删除文件
os.removedirs(path)
#删除空文件夹
shutil.rmtree(path)
#递归删除文件夹
路径连接:os.path.join(a,b,...)
4. csv
reader:
import csv
f = open('./test.csv','r')
reader_csv = csv.reader(f)
reader_csv = list(reader_csv)
for a, b, c in reader_csv:
print(a,b,c)
f.close()
writer:
import csv
f_o = open('./out.csv','w')
writer = csv.writer(f_o)
writer.writerow([a,b,c,d])
f_o.close()