Apr-27-2018, 08:23 PM
In the past, I would have suggested
glob
, but now we have pathlib
, which is fantastic. Here's an example:from pathlib import Path current_dir = Path(".") # iterate over all objects in this folder for obj in current_dir.iterdir(): # skip sub-folders if obj.is_file(): # open the file with open(obj) as f: # print the first line of the file for line in f: print(f"{obj} => {line}") break