NameError:名称“ savefile”未定义

时间:2019-06-07 18:12:18

标签: python-3.x function

这是我的代码,我在尝试使其运行时遇到问题。尝试执行时,我总是失败:

我引用此函数的方式与尝试引用此函数的方式相同?我不知道发生了什么事?

####解析结果
Traceback (most recent call last):
  File "masscanner.py", line 49, in <module>
    main()
  File "masscanner.py", line 43, in main
    file = write_file(savefile)
NameError: name 'savefile' is not defined



def write_file(savefile):
    print('\n\n########## WRITING FILE ##########\n')
    fh = open("endpointslist", "w")
    for i in savefile:
        fh.write(i[0])
        fh.write('\n')

def main():
    """ Main program """
    results = find_endpoints()
    ipportset = parse_results(results)
    fh = write_file(savefile)
    pprint(ipportset)
    return 0

if __name__ == "__main__":
    main()

1 个答案:

答案 0 :(得分:0)

可能只是错字。不应该是write_file(ipportset)。在上下文中,变量savefile来自无处,因此给您错误NameError: name 'savefile' is not defined