Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python csv写入新的附加文件而不替换旧文件_Python_Csv_Csv Write Stream - Fatal编程技术网

python csv写入新的附加文件而不替换旧文件

python csv写入新的附加文件而不替换旧文件,python,csv,csv-write-stream,Python,Csv,Csv Write Stream,我试图编写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

我试图编写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()
但是,有一个错误 “打开时(方向,cvs_文件名+”“results.csv”“w')作为结果文件: TypeError:需要一个整数(获取类型str)”


非常感谢你的帮助

打开的第一个参数是文件的整个路径,包括目录。 试一试

with open(direction + cvs_file_name + '_results.csv', 'w') as resultFile:
    etc