1、在脚本的时候,考虑到把测试结果与脚本、数据进行分开处理,即想到把脚本运行的结果都放入到result.txt的文档处理;
2、在这其中由于路径的问题,导致读入txt文档为乱码;
3、在读入的文档中写入运行电脑的本机IP:localIp=socket.gethostbyname(socket.gethostname());
4、获取运行脚本的时间:t=time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())),精确读取到年月日时分;
5、tes=[] 定义一个数据,把txt中的内容看做一个数组;
tes.append("Ip地址为:"+localIp+" , "+"时间:"+t+", "+"结果:"+re+ "
")
把读取到的类型添加到数组中;

1 #_*_encoding:utf-8_*_ 2 import os,time 3 import socket 4 def rest(re): 5 localIp=socket.gethostbyname(socket.gethostname()) 6 print localIp 7 t=time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())) 8 print t 9 tes=[] 10 tes.append("Ip地址为:"+localIp+" , "+"时间:"+t+", "+"结果:"+re+ " ") 11 print tes 12 try: 13 #fobj=open("result.txt",'a') 14 fobj=open("D:/svn_QA/eclipse_workspace/PythonCase/src/Data_init/result.txt",'a') 15 except IOError: 16 print"result.txt file open error" 17 else: 18 #file("./a.txt",'w').writelines(tes) 19 # fobj.write(' '+tes) 20 fobj.writelines(tes) 21 fobj.close() 22 print"ok?" 23 24 #rest(u" ting test BUG")