我有以下功能:
def createListofParts(testbenchParts, testbench, ttype):
partList = []
for part in ttype:
for root, subFolders, files in os.walk(os.path.join(testbenchParts, part)):
for file in files:
if file.endswith('.svn-base'):
pass
elif file.endswith('all-wcprops'):
pass
elif file.endswith('entries'):
pass
else:
partList.append(os.path.join(root, file))
createMatchTuples(partList, testbench)
def createMatchTuples(partList, testbench):
XMLlist = glob.glob(os.path.join(testbench, 'Scripts', "*.xml"))
matchList = []
for part in partList:
matches = 0
for xmlFile in XMLlist:
xml = open(xmlFile, 'r')
t = re.findall('/' + os.path.split(part)[1], xml.read().replace('\\','/'))
matches = matches + len(t)
xml.close()
matchList.append((os.path.split(part)[1], matches))
print matchList
print type(matchList)
return matchList
打印元组列表,然后键入= List
此功能称为
matchList = functions.createListofParts(testbenchParts, testbench, ttype)
print matchList
print type(matchList)
但现在打印None,即matchList从1st函数中的List转换为None!
我只是不明白这里发生了什么
任何帮助将不胜感激
答案 0 :(得分:2)
createListofParts
没有返回,因为所有函数都没有返回值,默认情况下它返回None,因此matchList = functions.createListofParts(testbenchParts, testbench, ttype)
将matchList
设置为None
,你需要到return createMatchTuples
:
def createListofParts(testbenchParts, testbench, ttype):
partList = []
for part in ttype:
for root, subFolders, files in os.walk(os.path.join(testbenchParts, part)):
for file in files:
if file.endswith('.svn-base'):
pass
elif file.endswith('all-wcprops'):
pass
elif file.endswith('entries'):
pass
else:
partList.append(os.path.join(root, file))
return createMatchTuples(partList, testbench) # <- return
答案 1 :(得分:2)
那是因为createListofParts
没有return语句而在python中,默认情况下,如果没有return语句,则函数返回None
。