2017-03-08 57 views
-1

我正在讨论许多包含相同源代码的类似Makefiles。我试图找出一个特定的源文件中 多少项目存在我想是这样的:。
foo.c的4 projA,projB,projC,projD]
bar.c 1 projC]
似乎我需要为每个makefile创建一个新的lstOfProjects,并且所有'我正在做的是删除它。 我已经尝试了很多其他的方法 元组可以有一个列表作为它的一个元素?带有列表作为维之一的多维列表

for file in listOf Makefiles 
for line in Makeifle 
find code file (.c or .h) 


    try: 
     index = lstFilenames.index(strFilename)  # to determine if I have seen this file name yet 
     # Yes the file name is already in list 
     lstOfFile = lstProjectNames[index]   # get list of projects that this file is seen in 
     try: 
      fileIndex = lstOfFile.index(myProject) # check to see if the project is in the project list 
     except: # project not in list 
      lstCount[index] +1      # add one to count - I am counting the number of projects this file appears 
      lstOfProjects.append(myProject)   # append the new project to list 
    except: # file name not found in list 
      lstFilenames.append (strFilename)  # put file in file name list 
      lstCount.append(1)      # set count to one 
      lstOfProjects.append(myProject)   # add project name to project list 

#************************************************************************** End of makefile 
lstProjectNames.append(lstOfProjects) # add project list to this list (this list in indexed with teh file names and the counts) 
del lstOfProjects[:] 
+0

甚至消除德尔和移动lstProjectNames.append删除(lstOfProjects )在第二行的最后一行除外。我仍然得到不正确的答案。我觉得我无法在我的lstOfProjects中获得新项目列表,就好像myProjects在我获得新文件时从未获得新列表一样。所有这些变量声明为 = [] –

回答

0

del lstOfProjects[:]行是罪魁祸首,因为你的lstProjectNames是拿着referencelstOfProjects,一旦你删除它的内容,它在lstProjectNames

+0

我想我需要为每个文件新的lstOfProjects。那我该怎么做?因为我所有的文件都有相同的Projects列表,并且我知道不是真实的我想要的是:
CMD_AUTH.h ['ARC',] Labortex.c ['ARC','AFO '] –

+0

尝试用'lstOfProjects = []'替换'del lstOfProjects [:]'' 这将使您的'lstOfProjects'变量指向程序中新创建的列表,而旧列表将保留在您的'lstProjectNames ' – Nether

+0

谢谢虚空。那是我错过的那篇文章(以及一些小的逻辑问题):) –