我編寫了以下提取信息的代碼。文件并根據其第二列對象按字母順序排序:import csvimport operatorimport sysdef re_sort(in_file='books.csv', out_file='books_sort.csv'): data = csv.reader(open('books.csv', newline=''), delimiter=',') header = next(data) sortedlist = sorted(data, key=operator.itemgetter(1)) with open("books_sorted.csv", "w", newline='') as csvfile: cvsWriter = csv.writer(csvfile, delimiter=',') cvsWriter.writerow(header) cvsWriter.writerows(sortedlist)每當我嘗試在命令行上運行此代碼時,都會出現錯誤TypeError:'newline'是此函數的無效關鍵字參數。你們看到發生這種情況的原因了嗎?以下是文件中內容的結構化版本:Title, Author, Publisher, Year, ISBN-10, ISBN-13Automate the..., Al Sweigart, No Sta..., 2015, 15932..., 978-15932...Dive into Py..., Mark Pilgr..., Apress, 2009, 14302..., 978-14302..."Python Cook..., "David Bea..., O'Reil..., 2013, 14493..., 978-14493...Think Python..., Allen B. D..., O'Reil..., 2015, 14919..., 978-14919..."Fluent Pyth..., Luciano Ra..., O'Reil..., 2015, 14919..., 978-14919...
添加回答
舉報
0/150
提交
取消