cwisbg

Python Read File

Dec 29th, 2011
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1.  fname = 'tmp.txt'
  2.  # Read the file and get each line as an array item
  3.  src = open(fname, 'r').readlines()
  4.  src = [line.strip() for line in src]
  5.  # Loop and split the line into items
  6.  for line in src:
  7.     data = line.split(',')
  8.     name = data[0]
  9.     pos = [ float(d) for d in data[1:4] ] # Get elements 1,2,3 as pos and convert them from string to float
  10.     rot = [ float(d) for d in data[4:7] ] # Get elements 4,5,6 as rotation and convert
  11.     scale = [ float(d) for d in data[7:] ] # Get elements from 7 to the end as scale and convert
  12.     print name, pos, rot, scale
Advertisement
Add Comment
Please, Sign In to add comment