[Solved] Want to read sequential lines in a file and do some mathematical calculation [closed]


Even though 5 persons down voted my question, I found my on way to solve the problem.
Here is the code which I used. It is written in Python.

enter codefrom numpy import *
from math import *
import operator

f = open('Data_Genergy_26.txt', 'r')
lines = f.readlines()
# initialize some variable to be lists:
r = []
ro = []
E =[]

# scan the rows of the file stored in lines, and put the values into some variables:
for line in lines:
    p = line.split()
    r.append(float(p[0]))
    ro.append(float(p[1]))
#Subtracting the current and previous item in a list
def foo(it):
    it = iter(it)
    t = it.next()
    for s in it:
        yield t, s
        t = s        
list(foo(r))
E=[x[1] - x[0] for x in foo(r)]
#print E
#Cubing all elements in a list
def cube(E):
    return [i ** 3 for i in E]
#print cube(E)
#computing total energy
z =[a*b for a,b in zip(cube(E),ro)]
z[:] = [x*4/3*pi for x in z] 
z.append(0.0) #for making r, ro, and z of same dimension
#print z     

DataOut = column_stack((r,ro,z))
savetxt('output.dat', DataOut)

If there is any better way to implement this please inform me.
Thanks

solved Want to read sequential lines in a file and do some mathematical calculation [closed]