Python 2.7 在每次运行时创建csv文件

Python 2.7 在每次运行时创建csv文件,python-2.7,csv,Python 2.7,Csv,我有一个应用程序,它最终创建csv文件来保存结果。我希望我的应用程序在每次运行时生成不同的csv文件 def writeToCSVFile(self,csvFilePath,testResultList): #Open a CSV file object reportname = "toxedo_report0.csv" csvFilObj=open(csvFilePath+reportname,"wb") #writing CSV file with the s

我有一个应用程序,它最终创建csv文件来保存结果。我希望我的应用程序在每次运行时生成不同的csv文件

def writeToCSVFile(self,csvFilePath,testResultList):
    #Open a CSV file object
    reportname = "toxedo_report0.csv"
    csvFilObj=open(csvFilePath+reportname,"wb")
    #writing CSV file with the statistical values
    mywritter=csv.writer(csvFilObj)
    for rowVal in testResultList:
        mywritter.writerows(rowVal)
    #Closing the CSV file object
    csvFilObj.close()
testResultList是一个类型列表。有没有办法避免硬编码报告名称?我想知道如何在每次运行时创建不同的报告

first run - C:/report/toxedo_report0.csv
            C:/report/toxedo_report1.csv
            C:/report/toxedo_report2.csv

只需使用一个附加参数
计数器

def writeToCSVFile(self,csvFilePath,testResultList, counter):
    #Open a CSV file object
    reportname = "toxedo_report{}.csv".format(counter)
    csvFilObj=open(csvFilePath+reportname,"wb")
    #writing CSV file with the statistical values
    mywritter=csv.writer(csvFilObj)
    for rowVal in testResultList:
        mywritter.writerows(rowVal)
    #Closing the CSV file object
    csvFilObj.close()
这是一条重要的路线:

reportname = "toxedo_report{}.csv".format(counter)
{}
计数器中的
将替换为数字

现在这样称呼:

首次运行:

inst.writeToCSVFile(csvFilePath, testResultList, 0)
第二轮:

inst.writeToCSVFile(csvFilePath, testResultList, 1)

这里的
inst
是一个类的实例,该类的方法是
writeToCSVFile

Muller Yes it dit。谢谢:)