函数NameError未定义

时间:2014-09-10 07:09:54

标签: python

我是python的新手,我在下面的脚本中收到此错误:

NameError: name 'csv_name_for' is not defined

def cvs_name_for(date):
    return "abuse_{0}.csv".format(date) 

def export_to_csv(complaints, date):    
    with open("{0}/{1}".format(CSV_DIR, csv_name_for(date)), "w") as csvfile:
    # do stuff

有什么问题?

1 个答案:

答案 0 :(得分:1)

您的函数名称为cvs...,并且您致电csv...。 修正:

def csv_name_for(date):
    return "abuse_{0}.csv".format(date) 

def export_to_csv(complaints, date):    
    with open("{0}/{1}".format(CSV_DIR, csv_name_for(date)), "w") as csvfile:
    # do stuff