A
alex.hanga
Hello!
I'm new here and fairly new to Python. I am attempting to read a data file into python and adding it to a 2D list to make it easy to use further down the line.
My data file is just 7 numbers in a row seperated by commas and each bulk of data is seperated by the sign @ to indicate that the data from this pointon should be stored into a new part of the 2D list.
1,1,1,1,1,1,1
2,2,2,2,2,2,2
@
3,3,3,3,3,3,3
4,4,4,4,4,4,4
After reading the file, the way I imagine the data to be shown would be in this manner:
data[0][0] = (1,1,1,1,1,1,1)
data[0][1] = (2,2,2,2,2,2,2)
data[1][0] = (3,3,3,3,3,3,3)
data[1][1] = (4,4,4,4,4,4,4)
This way it will be easy to loop across the data when I use it in Blender.
My code looks like this;
------------------------------
object_data = []
object_data.append([])
for rows in data.splitlines():
elems = rows.split(',')
if elems[0] != "@":
object_data.append((float(elems[0]),float(elems[1]),
float(elems[2]),float(elems[3]),float(elems[4]),
float(elems[5]),int(elems[6])))
else:
**start on object_data[1][j] and loop over it all again**
I'm new here and fairly new to Python. I am attempting to read a data file into python and adding it to a 2D list to make it easy to use further down the line.
My data file is just 7 numbers in a row seperated by commas and each bulk of data is seperated by the sign @ to indicate that the data from this pointon should be stored into a new part of the 2D list.
1,1,1,1,1,1,1
2,2,2,2,2,2,2
@
3,3,3,3,3,3,3
4,4,4,4,4,4,4
After reading the file, the way I imagine the data to be shown would be in this manner:
data[0][0] = (1,1,1,1,1,1,1)
data[0][1] = (2,2,2,2,2,2,2)
data[1][0] = (3,3,3,3,3,3,3)
data[1][1] = (4,4,4,4,4,4,4)
This way it will be easy to loop across the data when I use it in Blender.
My code looks like this;
------------------------------
object_data = []
object_data.append([])
for rows in data.splitlines():
elems = rows.split(',')
if elems[0] != "@":
object_data.append((float(elems[0]),float(elems[1]),
float(elems[2]),float(elems[3]),float(elems[4]),
float(elems[5]),int(elems[6])))
else:
**start on object_data[1][j] and loop over it all again**