python 常用

1.  文件操作

按文件名从指定的文件目录(含子目录),搜索到文件,并拷贝到另一指定目录下

  1. # coding=utf-8  
  2.   
  3. import os  
  4.   
  5. def search(path=".", name="1"):  
  6.     for item in os.listdir(path):  
  7.         item_path = os.path.join(path, item)  
  8.         if os.path.isdir(item_path):  
  9.             search(item_path, name)  
  10.         elif os.path.isfile(item_path):  
  11.             if name in item:  
  12.                 print(item_path)  
  13.                 destfilepath = "c:\\test3"
  14.                 copycommand = 'copy %s %s'%(item_path,destfilepath)
  15.                 if os.system(copycommand) == 0:
  16.                     print('ok')
  17.                 else:
  18.                      print('err')
  19.   
  20. if __name__ == "__main__":  
  21.     srcpath = "c:\\test1"
  22.     filelist = os.listdir(srcpath)
  23.     for filename in filelist
  24.         imgname = filename.replace('json','jpg')
  25.        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

3. python 安装路径查询

>>>import sys

>>>sys.path


猜你喜欢

转载自blog.csdn.net/u012968002/article/details/78923846