python读yaml文件,excel文件,csv文件

import csv

import openpyxl
import yaml


def get_yaml_data_dict(self, file):
    '''
    读yaml中的文件数据
    :param file:
    :return:
    '''
    with open(file, mode="r", encoding="utf8") as file:
        data = yaml.safe_load(file.read())
    return data

def get_excel_data(self,file,sheet_name):
    '''
    从excel文件中获取数据
    :param file:
    :param sheet_name:
    :return:
    '''
    wb = openpyxl.load_workbook(file)
    get_sheet = wb[sheet_name]
    one_line_data_list = []
    all_line_data_list = []

    # for i in range(get_sheet)
    status = True
    for get_tuple_cell in get_sheet:
        if status:
            status = False
            continue
        for get_cell in get_tuple_cell:
            one_line_data_list.append(get_cell.value)
        one_line_data_tuple = tuple(one_line_data_list)
        one_line_data_list.clear()
        all_line_data_list.append(one_line_data_tuple)

    return all_line_data_list
    
def get_csv_data_list(self,file):
    '''
    csv方式读文件
    :param file:
    :return:
    '''
    all_line_data_list = []
    with open(file,mode="r",encoding="urf-8") as file:
        data = csv.reader(file)
        for get_line_list in data:
            get_line_tuple = tuple(get_line_list)
            all_line_data_list.append(get_line_tuple)
    return all_line_data_list

 

你可能感兴趣的:(python)