[英]Function returning None - from list
我有以下功能:
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从第一个函数中的List转换为None!
我只是不明白这里发生了什么
任何帮助将不胜感激
createListofParts
没有返回值,因此所有没有返回值的matchList = functions.createListofParts(testbenchParts, testbench, ttype)
默认情况下返回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
那是因为createListofParts
没有return语句,并且在python中,默认情况下,如果没有return语句,则函数将返回None
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.