zoukankan      html  css  js  c++  java
  • jQuery火箭图标返回顶部代码

    1、python读写csv文件

     1 import csv
     2 
     3 #读取csv文件内容方法1
     4 csv_file = csv.reader(open('testdata.csv','r'))
     5 next(csv_file, None)    #skip the headers
     6 for user in csv_file:
     7     print(user)
     8 
     9 #读取csv文件内容方法2
    10 with open('testdata.csv', 'r') as csv_file:
    11     reader = csv.reader(csv_file)
    12     next(csv_file, None)
    13     for user in reader:
    14         print(user)
    15 
    16 #从字典写入csv文件
    17 dic = {'fengju':25, 'wuxia':26}
    18 csv_file = open('testdata1.csv', 'w', newline='')
    19 writer = csv.writer(csv_file)
    20 for key in dic:
    21     writer.writerow([key, dic[key]])
    22 csv_file.close()   #close CSV file
    23 
    24 csv_file1 = csv.reader(open('testdata1.csv','r'))
    25 for user in csv_file1:
    26     print(user)

    2、python读写excle文件

     需要先用python pip命令安装xlrd , xlwt库~

     1 import xlrd, xlwt   #xlwt只能写入xls文件
     2 
     3 #读取xlsx文件内容
     4 rows = []   #create an empty list to store rows
     5 book = xlrd.open_workbook('testdata.xlsx')  #open the Excel spreadsheet as workbook
     6 sheet = book.sheet_by_index(0)    #get the first sheet
     7 for user in range(1, sheet.nrows):  #iterate 1 to maxrows
     8     rows.append(list(sheet.row_values(user, 0, sheet.ncols)))  #iterate through the sheet and get data from rows in list
     9 print(rows)
    10 
    11 #写入xls文件
    12 rows1 = [['Name', 'Age'],['fengju', '26'],['wuxia', '25']]
    13 book1 = xlwt.Workbook()   #create new book1 excle
    14 sheet1 = book1.add_sheet('user')   #create new sheet
    15 for i in range(0, 3):    
    16     for j in range(0, len(rows1[i])):
    17         sheet1.write(i, j, rows1[i][j])
    18 book1.save('testdata1.xls')   #sava as testdata1.xls
  • 相关阅读:
    bite one's tongue
    你以为你以为的教育是教育吗?[转]
    使用ngnix通过uwsgi app容器部署django项目
    使用ngnix通过uwsgi app容器部署django项目
    vue作为前端的静态代码与后端融合
    linux下的下载器软件
    git的gui client终端
    java 查找bug的工具 SpotBugs 和 Findbugs
    awesome c, awesome c++
    加密货币即时交换平台 Changelly vs ShapeShift vs CoinSwitch vs ChangeNOW
  • 原文地址:https://www.cnblogs.com/cnkemi/p/8671493.html
Copyright © 2011-2022 走看看