Reputation: 313
I have the following function:
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
Which prints a list of tuples and then type = List
This function is called
matchList = functions.createListofParts(testbenchParts, testbench, ttype)
print matchList
print type(matchList)
but now prints None, ie the matchList is converted from List in 1st function to None!
I just don't understand whats going on here
Any help will be appreciated
Upvotes: 0
Views: 73
Reputation: 1603
Well that's because createListofParts
does not have a return statement and in python, by default, if there's no return statement, a function returns None
.
Upvotes: 2
Reputation: 180471
createListofParts
has no return so as all functions that don't have a return value, it returns None by default so matchList = functions.createListofParts(testbenchParts, testbench, ttype)
sets matchList
to None
, You need to 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
Upvotes: 2