我正在尝试从main ...中调用类中定义的函数。我可以这样做吗?
class file_process:
def findb(self, id):
....
def main():
id = sys.argv[2]
file_process.findb(id)//how to call findb function from main,this is giving an error
答案 0 :(得分:2)
由于finddb
是方法,您需要在file_process
的实例上调用它:
file_process().finddb(id)
我强烈建议您继续学习Python和课程,在继续之前我可以推荐Python tutorial。
答案 1 :(得分:1)
您需要先创建一个类的实例:
process = file_process()
process.findb(id)