So i'm trying to learn Python and at the same time write some code to help myself out with some mundane tasks. so i have a function which works just fine if i use the print statement to display just what i need, but when i replace the "print" statement for a "return" i only get the first element in the list, i know its because "return" causes the function to exit, but i have no idea how i can get this to return the rest of the elements. i have tried lots of things and been now reading for hours :( and still getting no further. objective: To read all the "*.common" files in a directory and then compare them with a text file containing some names, and if they match return the name of the *.common file so i can use it in another function as a variable. code i have thus far
# This method gets the list of common files....
def get_common_files():
path = (config_home)
files = []
for r, d, f in os.walk(path):
for file in f:
if '.common' in file:
files.append(file)
for f in files:
return files
new_file = get_common_files()
def build_default_manifest():
for line in fileinput.FileInput(new_manifest):
for name in new_file:
if line.strip() in name:
print(name) # works as it should and displays all that i need
return name # only shows me the first element
good_name = build_default_manifest()
print(good_name)
i hope i've provided all that i need to but if not please feel free to comeback to me...