Python Forum

Full Version: Class Modules, and Passing Variables: Seeking Advice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(Mar-02-2018, 02:33 PM)buran Wrote: [ -> ]concise code is always better and much easier to follow :-)

That all depends on who's trying to read it. Smile

I can't imagine any programmer who would find my coding style difficult to read. To the contrary, a raw beginner should be able to follow my code. And that's what I want.
Sorry but that code with comment is 21 lines and messy Dodgy
It's just reading a file into a list,the 3 lines from @Grib do the same in a much nicer way.
Just to make it clear,commenting when not needed can make code less readable.
range(0,len(words_raw)): is not good Never use "for i in range(len(sequence))

If need comments,try to use doc string.
def read(self, file_path):
    '''Read a file to a list and split on new lines(removed)'''
    with open(file_path) as stream_reader:
        return [line.strip() for line in stream_reader if line.strip()]
Pages: 1 2 3