【发布时间】:2022-01-13 08:30:34
【问题描述】:
我做了一个如下的类:
class Plugins:
def __init__(self):
pass
def voter_rep(self, loc, start_header, end_header):
self.loc = loc
ocr_xml = AbbyyXML(loc)
xml_doc = XMLDoc(ocr_xml, CONSTANTS)
xml_doc.split_words("", False)
self.start_header = start_header
self.end_header = end_header
header_pages = xml_doc.se_page(start_header, end_header)
## and stuff
voter_dict = {'Voter':[], 'Record_Key':[], 'Comments':[]}
## and stuff
return voter_dict, rep_dict
如果我在类之外单独运行方法函数,它完全可以正常工作,即如果我将函数编写为:
def voter_rep(loc, start_header, end_header):
ocr_xml = AbbyyXML(loc)
xml_doc = XMLDoc(ocr_xml, CONSTANTS)
xml_doc.split_words("", False)
header_pages = xml_doc.se_page(start_header, end_header)
## and stuff
voter_dict = {'Voter':[], 'Record_Key':[], 'Comments':[]}
## and stuff
return voter_dict, rep_dict
仅在函数中,我摆脱了self,只有voter_rep(loc, start_header, end_header),但是当我想从类中调用它时,我执行plugins.voter_rep(loc, start_header, end_header),它不起作用,它返回:
NameError: name 'plugins' is not defined
我想知道为什么我的函数可以自己工作但不能从类中调用?
【问题讨论】: