-1

我有一个要通过 processTestFile() 函数运行的文件名列表,该函数返回我要存储的结果字典:

 # Count success or failure of test cases
  counts = {
    "success": 0,
    "failure": 0 
    }

主流程循环如下所示:

for fileName in all_files(fileReferences["testCasesPath"],"*.txt") :
    print "\n\nRunning test case file = ", fileName
    myCounts = processTestFile(fileName)

我在想类似的东西:

  myArray = {}
  myArray[fileName] = myCounts

我会引用为:

for name in myArray
    print name, myArray[name] ["success"], myArray[name] ["failure"]

我怀疑这段代码会起作用。你有什么建议?

4

1 回答 1

1

myArray是 a 的奇怪名称dict。确保在循环对其进行初始化

myArray = {}
for fileName in all_files(fileReferences["testCasesPath"], "*.txt"):
    print "\n\nRunning test case file = ", fileName
    myCounts = processTestFile(fileName)
    myArray[fileName] = myCounts

for name, value in myArray.items()
    print name, value["success"], value["failure"]
于 2012-06-25T00:36:10.177 回答