Is there a way to use rhino scrpit, or python script to just import certain lines of a csv file. Meaning that the script specifies lines 2-10, then stops reading the csv. Thanks.
The ReadDelimitedFile method will read the entire csv file into an array. Then you can just iterate through the array looking for the records you want.
I suppose you could do something like the following, but I don’t know if it actually gets you anything…
–Mitch
import rhinoscriptsyntax as rs
def TestReadLineNumbers():
filepathname=rs.OpenFileName("CSV file to import", "Text Files (*.csv)|*.csv")
if not filepathname: return
start=rs.GetInteger("Start at line number",1,1)
if start is None: return
end=rs.GetInteger("End at line number",start,start)
if end is None: return
file=open(filepathname)
start-=1 ; end-=1
line_list=[]
for i,line in enumerate(file):
if i<start: continue
if i>end: break
line_list.append(line)
file.close()
print line_list
TestReadLineNumbers()