I am using Python's regex to extract paths from a file and then trying to append the paths into a single list. The paths are specified in different lines in the file (options) as follows:
EXE_INC = \
-I$(LIB_SRC)/me/bMesh/lnInclude \
-I$(LIB_SRC)/mTools/lnInclude \
-I$(LIB_SRC)/dynamicM/lnInclude
The function that I have is:
def libinclude():
with open('options', 'r') as options:
for lines in options:
if 'LIB_SRC' in lines:
result = []
lib_src_path = re.search(r'\s*-I\$\(LIB_SRC\)(?P<lpath>\/.*)', lines.strip())
lib_path = lib_src_path.group(1).split()
result.append(lib_path[0])
print result
return (result)
The output that I am getting is:
['/me/bMesh/lnInclude']
['/mTools/lnInclude']
['/dynamicM/lnInclude']
However, as you can see I get three different lists, each obtained for one of the lines in the file, options. Is there a way to get these three paths in one list so that the values are available outside the function.