Running Sum script

Juli Dolzhenko juli.dolzhenko at gmail.com
Fri Sep 4 15:30:35 EDT 2009


On Sep 4, 2:52 pm, "Rami Chowdhury" <rami.chowdh... at gmail.com> wrote:
> Could you let us know what kind of error you are getting?
>> I don't know if this is your error, but this line won't run:
>> > readData = formisanoOpen.readLines()
>> Since Python is case-sensitive, you would need a lower-case 'l' in
> 'readlines()' -- perhaps that would solve your problem?
>>>> On 2009年9月04日 11:26:06 -0700, Jul <sneaky... at gmail.com> wrote:
> > On Sep 4, 2:21 pm, Stephen Fairchild <someb... at somewhere.com> wrote:
> >> 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
>> > thats what i have so far --
>> > #!/usr/bin/python
>> > import os.path
>> > #open up the file
> > formisanoOpen = open("formisano_num.txt", "r")
>> > #read in all the data into a list
> > readData = formisanoOpen.readLines()
>> > #set up a sum
> > sum = 0;
>> > #begin a loop
> > for trial in readData:
>> > #the next line is indented (YA doesn't indent)
> > sum += int(trial)
>> > #loop is over, so unindent
> > #report the sum
> > print sum
>> > end
>> > but it doesnt want to run for some reason....
>> --
> Rami Chowdhury
> "Never attribute to malice that which can be attributed to stupidity" --
> Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

in the terminal i get a very strange "permission denied" error that
might not have anything to do with the code. I checked permissions for
the file and they are set to "read and write" so, again, I am really
not sure what going wrong.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /