beginner's python help

Niklas Norrthon niklas.norrthon at hotmail.com
Mon Sep 7 13:04:43 EDT 2009


On 6 Sep, 09:00, Maggie <la.f... at gmail.com> wrote:
> code practice:
>
> test = open ("test.txt", "r")
> readData = test.readlines()
> #set up a sum
> sum = 0;
> for item in readData:
>         sum += int(item)
> print sum
>
> test file looks something like this:
>
> 34
> 23
> 124
> 432
> 12
>

>>> sum(map(int, open('test.txt', 'r')))

Assuming the test file looks like above, and isn't stored in rtf
format or something like that. (Open the test file in the python
editor to check its contents).

/Niklas



More information about the Python-list mailing list