• CSV文件的基本操作


    # hanbb
    # come on!!!
    import csv
    
    # 文件的整体读取
    examplefile= open('E:\downloades.txt')    # 打开文件
    examplereader = csv.reader(examplefile)     # 读取文件  注意不能直接访问文件名字,必须先打开
    examplerdata = list(examplereader)          # 将返回为内容变成列表 操作
    
    # 文件的逐行读取
    openfile = open('E:\downloades.txt')      # 先打开
    readfile = csv.reader(openfile)             # 读取
    #for row in readfile:                        # 循环读取
        #print("row # " + str(readfile.line_num)+ ' ' +str(row))
    
    # 文件的写入
    file = open('E:\downloadwriter.csv','w',newline='')  # 打开的文件名称,写入模式,不写newline=''会出现行间距变大
    writerfile = csv.writer(file)                          # 写入命令
    writerfile.writerow(['name','address','city','state']) # 写入内容
    writerfile.writerow(['hbb','hangzhou','hangzhou','china'])
    file.close()                                           # 关闭文件
  • 相关阅读:
    Button与ImageButton的区别
    TCP、HTTP、Socket
    ASPX开发基础
    WebForm复杂控件
    Webform 内置对象 Session对象、Application全局对象,ViewState
    JavaScript
    .net
    postman-学习笔记
    2021第一天上班,立个flag
    js函数累加
  • 原文地址:https://www.cnblogs.com/hanbb/p/7891854.html
Copyright © 2020-2023  润新知