如何在Python中将一个函数变量用于另一个函数?

时间:2020-04-06 18:08:41

标签: python-3.x excel function variables automation

这是我的代码。...

import  openpyxl as xl
from openpyxl.chart import BarChart,Reference


    def spread_sheet(filename,sheetname):
        wb = xl.load_workbook(f'{filename}')   > i have to use these wb and sheet variables to all these functions down
        sheet= wb[f'{sheetname}']


    def total_horizontaly(row_start,row_end,col_start,col_end,Destination):
        tot=0
        for row in range(row_start,row_end+1):
            for col in range(col_start,col_end+1):
                cell =sheet.cell(row, col)
                tot += cell.value
            tot_marks =sheet.cell(row,f'{Destination}')
            tot_marks.value = tot


    def average_horizontaly(row_start,row_end,col_start,col_end,Desination):
        tot=0
        for row in range(row_start, row_end):
            for col in range(col_start, col_end):
                cell =sheet.cell(row, col)
                tot += cell.value
            avg=tot/(col_end+1-col_start)
            avg_marks=sheet.cell(row,f'{Desination}')
            avg_marks.value=avg


    def Save(filename):
        wb.save(f'{filename}')  

我曾经尝试过使用类“,”,它虽然有效,但不能满足我的结果

0 个答案:

没有答案