Interpreting your question as a general question of stylistics, my
experience is that a 3 line script often becomes a 10 line or a 50
line script at which point the direct printing will have to be
modified to create an internal data structure.

So on the whole I find it expedient to start with that assumption and
write it as:

def linesums(file):
return [sum(int(i) for i in l.split(';')) for l in open(file, 'r')]

Whether this one-liner is readable or not and how to make it more so
etc is probably bikeshedding.

More important questions are for example:
- Should you protect the open with a try
- When to list and when to generate(or)

All these are nice features of python but can lead to over-engineered
code

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!