Python同一类下的多个函数之间

函数main和函数save_excel都定义在一个类中。我想把函数save_excel的df对象单独拿到函数main里使用该如何操作呢?

img

答案都在下面这个图里了

img

以下答案引用自GPT-3大模型,请合理使用:
代码如下:

main.py

class main:

def save_excel(self, df):

将Excel文件保存到指定的文件夹

save_file = open('/Users/zhangjun/Desktop/test.xlsx', 'wb')

将数据写入到Excel文件

df.to_excel(save_file,index=False)

save_file.close()

def main():

创建一个名为test.xlsx的Excel文件

self.save_excel(df)

if name == 'main':

main()