Python编程(一)
来源:互联网 发布:澳门网络真人现场赌博 编辑:程序博客网 时间:2024/05/21 01:46
1.搜索当前目录文件
def is_file_contain_word(file_list, query_word): for _file in file_list: if query_word in _file: print _file print("Finish searching.")def get_all_file(folder_path): file_list=[] if folder_path is None: raise Exception("folder_path is None") for dirpath, dirnames, filenames in os.walk(folder_path): for name in filenames: file_list.append(dirpath + '\\' +name) return file_list
2.复制文件
shutil.copyfile("dpllucc.asc", "temp.txt")
3.查找替换
3.1根据excel表格创建字典
tranmessage = xlrd.open_workbook('landusetran.xlsx')table = tranmessage.sheet_by_index(0)former=[]for i in range(2): former.append(table.col_values(i)) for item in former[i]: former[i][former[i].index(item)]=(str(int(item)))transverter = dict(zip(former[0], former[1]))3.2替换文件中的内容
linedata = temp.readline()while linedata: datalist = linedata.split() line = '' for word in datalist: if word in transverter.keys(): line = line + word.replace(word, transverter[word]) + ' ' else: line = line + word + ' ' line =line[:-1] + '\n' resfile.write(line) linedata = temp.readline()temp.close();resfile.close()
0 0
- Python编程(一)
- python Socket编程(一)
- python 多线程编程(一)
- 《Python编程》笔记(一)
- Python语言编程(一)
- Python多线程编程(一)
- Python 网络编程 (一)
- python密码学编程(一)
- python核心编程(一)
- Python编程细节(一)
- Python 编程笔记(一)
- python核心编程(一)
- python高级编程(一)--多线程编程
- Python线程编程(一)线程对象
- Python线程编程(一)线程对象
- python核心编程学习笔记(一)
- python核心编程学习(一)
- python网络编程学习笔记(一)
- Sharepoint online 创建模板与使用模板
- DNR脑神经递质5合3阶段再生疗法是什么?
- 回调函数
- Objective-C基础之NSValue包装结构体
- PyMongo基本使用
- Python编程(一)
- HDU 1976 prime path
- 全站压缩(java)
- Hive 基础之:分区、桶、Sort Merge Bucket Join
- Android 从webview跳到本地activity
- javascript深入理解js闭包
- Storm详解二、写第一个Storm应用
- JavaSe基础XX03——数组
- Fly to basket 点击添加到右侧购物车,动画效果