Python Forum
Class Modules, and Passing Variables: Seeking Advice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Modules, and Passing Variables: Seeking Advice
#21
(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.
Reply
#22
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()]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unchangeable variables in a class? Calab 12 1,423 Sep-15-2023, 07:15 PM
Last Post: deanhystad
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 3,785 Nov-12-2021, 09:55 PM
Last Post: snippsat
  How to pass variables from one class to another hobbyist 18 10,397 Oct-01-2021, 05:54 PM
Last Post: deanhystad
  Acess variables from class samuelbachorik 3 1,868 Aug-20-2021, 02:55 PM
Last Post: deanhystad
  Passing Variables between files. victorTJ 3 2,223 Oct-17-2020, 01:45 AM
Last Post: snippsat
  New user seeking help EdRaponi 2 38,018 Jun-23-2020, 12:03 PM
Last Post: EdRaponi
  Class variables menator01 2 1,958 Jun-04-2020, 04:23 PM
Last Post: Yoriz
  Question about naming variables in class methods sShadowSerpent 1 1,964 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  Python 2.7 passing variables from functions zetto33 1 1,754 Mar-19-2020, 07:27 PM
Last Post: Larz60+
  Pythonic way to handle/spread alerts class in multiple modules psolar 11 4,487 Feb-12-2020, 04:11 PM
Last Post: psolar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020