zoukankan      html  css  js  c++  java
  • Python文件之----CSV

     1 # -*- coding:utf-8 -*-
     2 '''
     3 Created on 2015年4月20日
     4     
     5 @author: liuxue
     6 
     7 '''
     8 import csv
     9 import sys
    10 reload(sys)
    11 sys.setdefaultencoding('utf-8')
    12 '''
    13 valueList=[[]],双层列表,每一个元素代表一行数据
    14 '''
    15 
    16 def csvWrite(fileName="",mode="",valueList=[]):
    17     csvFile=file(fileName,mode)
    18     cstWriter=csv.writer(csvFile)
    19     for i in range(len(valueList)):
    20         temp=[]
    21         temp=valueList[i]
    22         cstWriter.writerow(temp)
    23     csvFile.close()
    24 
    25 def csvRead(fileName=""):
    26     csvFile=open(fileName,'r')
    27     line = csvFile.readline().strip('
    ')#如果有标题不想读取,可以重复这句
    28     valueList=[]
    29     while(line!=""):
    30         temp=line.split(',')
    31         valueList.append(temp)
    32         line = csvFile.readline().strip('
    ')
    33     csvFile.close()
    34     return valueList
    35 
    36 
    37 def main():
    38     valueList=[["","d"]]
    39     csvWrite("test.csv","wb",valueList)
    40     value=csvRead("test.csv")
    41     for i in range(len(value)):
    42         temp=value[i]
    43         print temp
    44         for j in range(len(temp)):
    45             print temp[j]
    46 
    47 
    48 if __name__=="__main__":
    49     main()
    50 
    51 '''
    52 输出:
    53 ['xe6x88x91', 'd']
    54 55 d
    56 '''
  • 相关阅读:
    测试管理工具
    测试用例--zy
    测试计划和测试用例
    测试用例
    软件测试基础
    异步任务 ---- django-celery
    图片验证码接口
    测试作业
    数据库原理
    HTTPS原理
  • 原文地址:https://www.cnblogs.com/moye13/p/4537494.html
Copyright © 2011-2022 走看看