我正在尝试编写 csv 文件并在每次用户使用它时创建一个新文件,而不是替换旧文件。此外,用户需要在开头输入他们的名字,所以我需要文件名是用户的名字。这是我的代码:
direction = "/Users/Desktop/"
cvs_file_name = str(self.entrySub.get()) ###'entrySub' is where users enter the name, and I use .get() to retrieve it.###
with open(direction, cvs_file_name+'_results.csv', 'w') as resultFile:
resultFileWrite = csv.writer(resultFile, quoting=csv.QUOTE_ALL)
resultFileWrite.writerow(['Subject', "Session"])
resultFileWrite.writerow([self.entrySub.get(), self.entrySes.get()])
resultFile.flush()
但是,有一个错误“with open(direction, cvs_file_name+'_results.csv', 'w') as resultFile: TypeError: an integer is required (got type str)”。
非常感谢您的帮助!