[Tutor] Import tabular data file and assign to variables

RenderPipe renderpipe at speedpost.net
Thu Sep 16 15:41:58 CEST 2004


I'm having difficulty trying to figure out how to read in tabular data
to variables.

I have a file with about 700 lines that look like this:
    -31.5227      7.7864    -74.4018     -2.4335     -8.7991
    -31.5227      7.7864    -74.4018     -2.4335     -8.7991

These are coordinates for a 3d object in 3 translation axis and 2
rotations axis. Each line is 1 frame in time.
I need to be able to assign each field value to a variable but I don't
understand how to parse the list.

Essentially what I need is 
Frame 1
transx = -31.5227
transy = 7.7864
transz = -74.4018
rotx = -2.4335
roty = -8.7991

Frame 2

I was thinking of creating a dictionary object for each frame but I do
not know how to extract the data in the colums and assing them to a
Here's what i have come up with so far:

import string

myfile = open("MyFile")
data = myfile.readlines()
for line in data:
        rs  = line.split("\t")
        print rs

The problem with this is it also prints \r\n characters. The example
output of this code is:
['    -31.5227      7.7864    -74.4018     -2.4335     -8.7991\r\n']
['    -31.5227      7.7864    -74.4018     -2.4335     -8.7991\r\n']

I appreciate any input you can offer.


More information about the Tutor mailing list