Running Sum script

Stephen Fairchild somebody at somewhere.com
Fri Sep 4 20:21:05 CEST 2009


Jul wrote:

> hello,
> 
> I have a .txt file that is in this format --
> 
> 12625
> 17000
> 12000
> 14500
> 17000
> 12000
> 17000
> 14500
> 14500
> 12000
> ...and so on...
> 
> i need to create a python script that will open this file and have a
> running sum until the end of file.

Untested:

with open("numbers.txt", "r") as f:
   print sum(int(x) for x in f)
-- 
Stephen Fairchild



More information about the Python-list mailing list