我的CSV write代码已停止将writer识别为有效

2024-06-09 02:04:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我的csv writer不想再工作了,它仍然创建一个文件,但它不会向文件中添加任何数据。我发现csv.writer(f)不起作用。弹出的错误是'AttributeError:'function'对象没有属性'writer'

我真的不知道出了什么问题。我用https://www.youtube.com/watch?v=s1XiCh-mGCA&t=165s作为我的模型。我也去了https://docs.python.org/3/library/csv.html看看他们是怎么写的,但我似乎找不出我和他们之间的主要区别。问这个我觉得像个傻瓜,但我好像听不懂

*编辑更多的内容,它不会让我张贴更多

def full():
    wks1 = gc.open('RubricAutomation').worksheet(sheetname[lb.curselection()[0]])
    marklist = list(zip(orgid[2:], mark[2:],late[2:])) #combines student ID and marks for CSV
    toplist = list(zip(names[2:], commentList[2:])) #combines student names and comments for D2L
    sorting = lambda toplist: toplist[0]
    toplist.sort(key=sorting)

    with open(location + asgnName + ".csv", 'w',  newline='') as f:  ## opens new csv file into location and adds name from gspread
        writer = csv.writer(f)
        writer.writerow(['OrgDefinedId', asgnName + " Points Grade", "End-of-Line Indicator"])
        for i in marklist:
            writer.writerow([ i[0],i[1] ,"#"])

Tags: and文件csvhttpsfornamesopenzip