zoukankan      html  css  js  c++  java
  • 读写TXT文档

    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")
    View Code
     
  • 相关阅读:
    Html语言基础
    acm练习(四)
    acm练习(三)
    acm练习(二)
    acm练习(一)
    android自定义控件属性
    android ViewGroup getChildDrawingOrder与 isChildrenDrawingOrderEnabled()
    java 用Arrays.binarySearch解读 快速定位数字范围
    android极光推送初步了解...
    GridView与ListView冲突
  • 原文地址:https://www.cnblogs.com/tyen0921/p/3628620.html
Copyright © 2011-2022 走看看