1. 文件操作
按文件名从指定的文件目录(含子目录),搜索到文件,并拷贝到另一指定目录下
- # coding=utf-8
- import os
- def search(path=".", name="1"):
- for item in os.listdir(path):
- item_path = os.path.join(path, item)
- if os.path.isdir(item_path):
- search(item_path, name)
- elif os.path.isfile(item_path):
- if name in item:
- print(item_path)
- destfilepath = "c:\\test3"
- copycommand = 'copy %s %s'%(item_path,destfilepath)
- if os.system(copycommand) == 0:
- print('ok')
- else:
- print('err')
- if __name__ == "__main__":
- srcpath = "c:\\test1"
- filelist = os.listdir(srcpath)
- for filename in filelist
- imgname = filename.replace('json','jpg')
- search("c:\\test2",imgname)
2. 发布
用 pyInstaller 将python文件 发布为 exe
3. numpy unique unionld enumerate
unique 去除重复数字并按一定顺序排列
unionld 联合两部分数据,并按一定顺序排列
enumerate
enumerate会将数组或列表组成一个索引序列。使我们再获取索引和索引内容的时候更加方便如下:
for
index
,
text
in
enumerate(
list
)):
print index , text
print index , text
3. python 安装路径查询
>>>import sys
>>>sys.path