issue with grep command

2009-09-03 Thread Jul
in tcsh terminal i have the following line of code

cat fileName.txt | grep "a"

which extracts all the instances of "a" from the file in the
terminal..

however when i am trying to create a txt while, i am unable to do so
for some reason..this is the syntaxt i am using --

cat fileName.txt | frep "a" > a.txt


file then appears in the folder, however, it can no be opened because
"the file is not in the right format"..

does anybody know how to correct this problem?

thanks so much
-- 
http://mail.python.org/mailman/listinfo/python-list


Running Sum script

2009-09-04 Thread Jul
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.

it sounds really simple its just for some reason i am having problem
with it.

i would really appreciate your help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running Sum script

2009-09-04 Thread Jul
On Sep 4, 2:21 pm, Stephen Fairchild  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
-- 
http://mail.python.org/mailman/listinfo/python-list