I'm just doing a bunch of Python exercises and there is an exercise where you should. given a directory name, iterate over the its 'special files' (containing the pattern _\w+_) and output their absolute paths.
Here's my code:
def get_special_paths(dir):
filenames = os.listdir(dir)
for filename in filenames:
if re.search(r'__\w+__', filename):
print os.path.abspath(os.path.join(dir, filename))
I joined the dir and filename as suggest in the examples but I don't see while the join() is needed. If I don't join the filename + dir, and instead pass abspath() only the filename, the output would be the same.