I have the following file I'm trying to manipulate.

```
 1  2 -3 5  10  8.2
 5  8  5 4  0   6
 4  3  2 3 -2   15
 -3 4  0 2  4   2.33
 2  1  1 1  2.5 0
 0  2  6 0  8   5

```

The file just contains numbers.

I'm trying to write a program to subtract the rows from each other and print the results to a file. My program is below and, `dtest.txt` is the name of the input file. The name of the program is `make_distance.py`.

```
from math import *

posnfile = open("dtest.txt","r")
posn = posnfile.readlines()
posnfile.close()

for i in range (len(posn)-1):
    for j in range (0,1):
        if (j == 0):
            Xp = float(posn[i].split()[0])
            Yp = float(posn[i].split()[1])
            Zp = float(posn[i].split()[2])

            Xc = float(posn[i+1].split()[0])
            Yc = float(posn[i+1].split()[1])
            Zc = float(posn[i+1].split()[2])
        else:
            Xp = float(posn[i].split()[3*j+1])
            Yp = float(posn[i].split()[3*j+2])
            Zp = float(posn[i].split()[3*j+3])

            Xc = float(posn[i+1].split()[3*j+1])
            Yc = float(posn[i+1].split()[3*j+2])
            Zc = float(posn[i+1].split()[3*j+3])

        Px = fabs(Xc-Xp)
        Py = fabs(Yc-Yp)
        Pz = fabs(Zc-Zp)
        print Px,Py,Pz

```

The program is calculating the values correctly but, when I try to call the program to write the output file,

```
mpipython make_distance.py > distance.dat

```

The output file (`distance.dat`) only contains 3 columns when it should contain 6. How do I tell the program to shift what columns to print to for each step j=0,1,.... 

For j = 0, the program should output to the first 3 columns, for j = 1 the program should output to the second 3 columns (3,4,5) and so on and so forth.

Finally the `len` function gives the number of rows in the input file but, what function gives the number of columns in the file? 

Thanks.