zoukankan      html  css  js  c++  java
  • Python 操作 Excel 、txt等文件

    #xlrd  读取excel
    
    import xlrd
    import os
    #获取文件路径
    filepath = os.path.join(os.getcwd(),'user_info')
    #获取文件名称
    filename = filepath + '/Mail_info.xlsx'
    ReadExcel = xlrd.open_workbook(filename)
    #查看 sheet 页
    #print(ReadExcel.sheet_names())
    #获取sheet页的两种方式
    #sheet1 = ReadExcel.sheet_by_index(0)
    #sheet2 = ReadExcel.sheet_by_name('sender')
    
    sender = ReadExcel.sheet_by_name('sender')
    receiver = ReadExcel.sheet_by_name('receiver')
    #第一列的值
    colList = sender.col_values(0)
    print(colList)
    #第一行的值
    rowList = sender.row_values(0)
    print(rowList)
    
    #单元格的值
    sender_cell = sender.cell(1,0)
    print(sender_cell.value)
    
    #列的长度
    rowMax = sender.row_len(1)
    print(rowMax)
    #ReadTxt_demo.py
    #读取 txt  文件
    
    def readTxt(filePath):
        fo = open(filePath,'r')
        lines = fo.readlines()
        for data in lines:
            name, pwd = data.split(',')
    
        return name,pwd
    
    filePath = 'userInfo.txt'
    re_name,re_pwd = readTxt(filePath)
    
    if __name__=="__main__":
        pass
  • 相关阅读:
    Senventh Week(补充完整)
    Sixth Week(补充完整)
    Fifth Week(补充完整)
    Fourth Week (补充完整)
    九大内置对象
    matlab 简单绘图
    matlab ./
    困惑
    【转】matlab中inf
    matlab x~=0
  • 原文地址:https://www.cnblogs.com/Skyyj/p/6762496.html
Copyright © 2011-2022 走看看