import pandas as pd
class main_class:
def __init__(self,data_frame):
self.data_frame = data_frame
def read_csv(self):
data_frame = pd.read_csv("outputfile.csv")
return data_frame
inc = main_class
print(inc.read_csv)通过运行此代码,我得到了未绑定的方法错误。
发布于 2018-03-20 15:10:34
您所看到的不是错误,而是函数的描述。
这个代码有几个问题。
main_class的实例。要解决上述两个问题,您需要添加()
inc = main_class()
# ^
print(inc.read_csv())
# ^现在您将得到一个TypeError错误,因为main_class.__init__需要一个参数。
main_class.__init__接受一个参数并将其存储到不被任何地方使用的self.data_frame。data_frame in read_csv与self.data_frame无关。object中的类:
类main_class(对象):.在底线中,您可能希望阅读Python教程,以重新讨论类和方法的基本思想是如何工作的。
https://stackoverflow.com/questions/49387666
复制相似问题