Thank you all for the help before. I now had completed a task (so I thought) in order to achieve the following: I needed to write a one liner which outputs filenames that have more than 10 characters and also their contents consists out of more than 10 lines. My code is the following:
import os; [filename for filename in os.listdir(".") if len(filename) > 10 and len([line for line in open(filename)]) > 10 if filename =! filename.endswith(".ipynb_checkpoints")]
The problem that exists is the following error:
[Errno 13] Permission denied: '.ipynb_checkpoints'
I tried to exclude the .ipynb_checkpoint-files but it still doesn´t work properly. Do you have any suggestions on how to exclude them or solve my problem? Thank you for your time!
Greetings.
The issue might be the order of your if statements,
String.endswith returns a boolean and cannot be compared to the string, and__pycache__files also cause errors so I added it.Some of the characters in ipynb files cause
UnicodeDecodeError: 'charmap' codec can't decodeerrors and decoding inLatin-1seemed to fix that. (UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>)you could try something like:
this solution seems to work but maybe a more general solution makes more sense.ie: PermissionError: [Errno 13] Permission denied