Code: Alles auswählen
def iter_project_paths(root_path):
return filter(is_project_path, os.listdir(root_path))
Code: Alles auswählen
def iter_project_paths(root_path):
return filter(is_project_path, os.listdir(root_path))
Nein in PROJECT_SUB_DIRS (sollten) sind die Unterverzeichnisse der Projekte die ja immer den gleichen Namen enthalten. Der Name der sich ändert ist ja nur der Projektname selber.snafu hat geschrieben: 2. In ``PROJECT_SUB_DIRS`` sind nicht die Ordernamen deiner Projekte enthalten (hier *keine* vollständige Pfadangabe, sondern wirklich nur den Namen des einzelnen Ordners).
Code: Alles auswählen
def iter_project_paths(root_path):
return (
is_project_path(os.path.join(root_path, sub_dir))
for sub_dir in os.listdir(PROJECT_SUB_DIRS)
)
Code: Alles auswählen
def iter_project_paths(root_path):
dirnames = (
os.path.join(root_path, sub_dir)
for sub_dir in os.listdir(PROJECT_SUB_DIRS)
)
return filter(is_project_path, dirnames)
Code: Alles auswählen
def is_project_path(path):
return os.path.isdir(path) and all(
os.path.isdir(os.path.join(path, sub_directory))
for sub_directory in PROJECT_SUB_DIRS
)
Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)) if function is not None and (item for item in iterable if item) if function is None.
Code: Alles auswählen
for curdir, dirs, files in os.walk(root_path):
if filename in files:
with open(filename, 'r') as lines:
if any(needle in line for line in lines):
print(curdir, dirs, files)
Code: Alles auswählen
for curdir, dirs, files in os.walk(root_path):
if filename in files:
with open(os.path.join(curdir, filename), 'r') as lines:
if any(needle in line for line in lines):
print(curdir, dirs, files)