python对文本文档的读写和删除操作-2
来源:互联网 发布:男朋友丁丁太大 知乎 编辑:程序博客网 时间:2024/05/04 18:59
项目需要,首先需要读取json格式存储的文本文档,该文本文档存在指定的目录中,该目录下有很多的文本文档,需要在文本文档中找到里面的calls数据,然后把calls数据返回,供robotframework 调用,然后在另一个测试用例中将calls数据和时间间隔写入另一个文本文档中。
#-*- coding:utf-8 -*-import osclass Write_in_Txt(object): def __init__(self): self._write_in_file = None def get_written_data(self, calls1, calls2): dict_call = {"calls_before" :calls1, "calls_after" :calls2} return dict_call def write_to_txt_file(self, file_path, dict_call, time_interval): if not os.path.exists(file_path): file_name = open(file_path, 'w') for key,value in dict_call.items(): print 'key',key print 'value',value file_name.write(key + ":" + value + '---') file_name.write('time_interval:' + time_interval) file_name.write('\n') file_name.close() else: file_name = open(file_path, 'a') for key,value in dict_call.items(): print 'key',key print 'value',value file_name.write(key + ":" + value + '---') file_name.write('time_interval:' + time_interval) file_name.write('\n') file_name.close()if __name__ == '__main__': current_dir = os.getcwd() print 'current_dir', current_dir file_path = current_dir +"\\" + "\\calls_collection.txt" write_in_file = Write_in_Txt() dict_data = write_in_file.get_written_data("10","11") write_in_file.write_to_txt_file(file_path, dict_data, "2016-08-01~2016-08-10") dict_data2 = write_in_file.get_written_data("5","6") write_in_file.write_to_txt_file(file_path, dict_data, "2016-05-01~2016-05-10")
0 0
- python对文本文档的读写和删除操作-2
- python对文本文档的读写和删除操作-1
- python 文本读写操作
- perl 对Excel2003文档的读写操作
- Python读写文本文档详解
- 【Python】Python对文件的读写操作
- Java文本文档的读写操作(复习笔记)
- Python(18):对文件的操作(读写、创建、拷贝、移动、删除)
- python 对EXCEL的读写操作
- python对excel文件的读写操作
- python里面对文件的读写操作
- C++对txt文本进行读写操作
- .net 对xml文件的读写,添加,修改,删除操作
- Python 对Excel操作读写
- JavaEE之使用DOM4J和XPath对xml文档的添加,删除,查询操作
- Python 中对XML 的基本的读写操作
- python实现对excel表的读写操作(一)
- Python读写文件、对文件操作系统的操作
- PHP程序设计读书笔记四
- 010——Struts2的国际化
- Android中检测手机制式和移动网络类型
- hibernate
- hdu 1732 Push Box(BFS)
- python对文本文档的读写和删除操作-2
- JS高级调试技巧:捕获和分析 JavaScript Error详解
- Open Source Virtual Reality ---Uniform Resource Locator
- android studio | openGL es 3.0增强现实(AR)开发 (5) GLSurfaceView浅解
- MySQL对数据的操作
- js中闭包的概念
- 乘法表输出文件
- hdu 1584 蜘蛛牌(DFS)
- 第一个powershell脚本