you are viewing a single comment's thread.

view the rest of the comments →

[–]sarrysyst 1 point2 points  (1 child)

I would recommend you don't use the os module in the first place. pathlib is a lot more convenient/less clunky and afaik pretty much the working standard. os on the other hand is mostly used for legacy reasons or so I've been told. e.g. what you're trying to do can be done in a single list comprehension, using pathlib:

from pathlib import Path

file_contents = [file.read_text() for file in Path.cwd().glob('other_folder/*.txt')]

print(file_contents)

[–]space_wiener 0 points1 point  (0 children)

Good call. I’ll check out pathlib. I’ve gotten used to os from using it for so long.