Re: A question about readability

2012-12-10 Thread rusi
On Dec 10, 3:03 pm, Jean-Michel Pichavant wrote: > - Original Message - > > On Dec 7, 6:46 pm, Marco wrote: > > > Hi all, do you think this code: > > > > $ more myscript.py > > > for line in open('data.txt'): > > >      result = sum(int(data) for data in line.split(';')) > > >      print(

Re: A question about readability

2012-12-10 Thread Jean-Michel Pichavant
- Original Message - > On Dec 7, 6:46 pm, Marco wrote: > > Hi all, do you think this code: > > > > $ more myscript.py > > for line in open('data.txt'): > >      result = sum(int(data) for data in line.split(';')) > >      print(result) > > > > that sums the elements of the lines of this

Re: A question about readability

2012-12-07 Thread rusi
On Dec 7, 6:46 pm, Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): >      result = sum(int(data) for data in line.split(';')) >      print(result) > > that sums the elements of the lines of this file: > > $ more data.txt > 30;44;99;88 > 11;17;1

Re: A question about readability

2012-12-07 Thread Steven D'Aprano
On Fri, 07 Dec 2012 14:46:03 +0100, Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): > result = sum(int(data) for data in line.split(';')) > print(result) [...] > is explicit enough? Do you prefer a clearer solution? Thanks in advance

Re: A question about readability

2012-12-07 Thread Roy Smith
In article , Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): > result = sum(int(data) for data in line.split(';')) > print(result) That sum() line is a bit of a mouthful. I would refactor it into something like this: > for line

A question about readability

2012-12-07 Thread Marco
Hi all, do you think this code: $ more myscript.py for line in open('data.txt'): result = sum(int(data) for data in line.split(';')) print(result) that sums the elements of the lines of this file: $ more data.txt 30;44;99;88 11;17;16;50 33;91;77;15 $ python3.3 myscript.py 261 94 216 is