elenorcoli opened this issue on Jun 09, 2007 · 5 posts
adp001 posted Sat, 09 June 2007 at 5:13 PM
Perhaps things would be simpler if you read your file line by line with "ReadLine".
Simpler and faster.
You can split each line into parts (see Split() in your manual) directly and fill your array with what you really need.
In python it may look like this:
<pre style="font-family:'courier new';">
def readIntoArray(filehandle, leading=False) :<br></br> """<br></br> Read data from a file (wavefront object format) int an array.<br></br> leading: the character preceeding a line of data ("v 0 0 0").<br></br> Lines starting with another characters than leading are ignored<br></br> if leading is set.<br></br> Returns a filled array.<br></br> """<br></br><br></br> ar = [] # define an empty array<br></br><br></br> for line in filehandle: # read line by line -<br></br> if not line : # skip empty lines<br></br> continue<br></br> first,x,y,z=line.split() # we assume that each line has 4 elements<br></br> # seperated by whitespace(s).<br></br><br></br> if leading and (leading != first):<br></br> continue<br></br><br></br> ar.append([x,y,z]) # append row of data to array<br></br><br></br> return ar # return created array<br></br><br></br><br></br>filehandle = open("my1FileWithData.obj")<br></br>array1 = readIntoArray(filehandle)<br></br>filehandle.close()<br></br><br></br>filehandle = open("my2FileWithData.obj")<br></br>array2 = readIntoArray(filehandle)<br></br>filehandle.close()