# untested
x = 1000
with open(path, 'rb') as fileobj:
data = [x.strip().split(' ') for x in fileobj.readlines()]
total_rows = len(data)
for n in xrange(1, total_rows):
first = int(data[n-1][0].strip())
second = int(data[n][0].strip())
print (second-first)/x
./rdiff.py
Traceback (most recent call last):
File "./rdiff.py", line 4, in <module>
with open(test.txt, 'rb') as fileobj:
NameError: name 'test' is not defined
I am getting the correct values but, i would like to add a 0 as the first row and also fix the error below
2
0
13
1
Traceback (most recent call last):
File
Traceback (most recent call last):
File "./new.py", line 11, in <module>
second = int(data[n][0].strip())
ValueError: invalid literal for int() with base 10: ''
# untested
x = 1000
with open(path, 'rb') as fileobj:
data = [[y for y in x.strip().split(' ') if y] for x in fileobj.readlines()]
total_rows = len(data)
for n in xrange(1, total_rows):
try:
first = int(data[n-1][0].strip())
second = int(data[n][0].strip())
print (second-first)/x
except ValueError:
print "couldn't convert a number to integer, row %s"%n
print data[n-1][0], data[n][0]