Hot answers tagged

3

Refactor the code so each file type gets it's own function for counting the words like excel_counter() and pdf_counter(). Then use a dict to map file extensions to the functions. Something like: def docx_counter(file): text = docx2txt.process(file) return len(text.split()) def txt_counter(file): f = open(file, "r") text = f.read() ...


3

I recommend using pathlib and Path objects instead of os, and you should use a context manager when manipulating files (e.g. with open("file.txt", "r") as file: ...). You also have a lot of repeating code when you're checking extensions, and you keep checking the rest of the if statements even if it's matched an earlier one. And the final else: pass does ...


2

in my opinion, the code is good, but I have some suggestions. com.github.coderodde.RemoteFile class com.github.coderodde.RemoteFile#download(java.io.File) The URISyntaxException in the method com.github.coderodde.RemoteFile#download(java.io.File) is never thrown and can be removed. In my opinion, the logic of this method should be extracted to an external ...


Only top voted, non community-wiki answers of a minimum length are eligible