I’ve just been asked to come up with a script to find files with a certain filename length. I’ve decided to try out Python for the first time for this task as I’ve always wanted to learn it.
I’ve got the script to find the files and append them to a text file but it does not write a line break for each new entry. Is there a way to do this as the current output is almost unreadable?
You just need to explicitly append a
'\n'each time you want a line break — if you’re appending to the output file in text mode, this will expand to the proper line separation where needed (e.g. Windows). (You could use os.linesep instead, if you had to output in binary mode for some reason, but that’s a pretty unusual use case — normally, text mode and\nare much better).