fastercsv and several row

L

Li Chen

Hi all,

I just try fastercsv and it works fine.

I use the codes below to print out the first columns of the first ten
rows. And it is OK. Question1) Is this the Ruby way to do that?
Question 2)what if I want to print out the first columns of row 20-30?


Thank you very much,

Li

####
i=1
FasterCSV.foreach('test.csv','rb') do |row|
puts row[0]
break if i==10
i+=1
end
####
 
J

James Gray

Hi all,
Hello.

I just try fastercsv and it works fine.
Great.

I use the codes below to print out the first columns of the first ten
rows. And it is OK. Question1) Is this the Ruby way to do that?

It's definitely one possible way. You could also use:

FCSV.open('test.csv') do |csv|
csv.each do |row|
puts row.first
break if csv.lineno >= 10
end
end
Question 2)what if I want to print out the first columns of row
20-30?

FCSV.open('test.csv') do |csv|
csv.each do |row|
puts row.first if csv.lineno >= 20
break if csv.lineno >= 30
end
end

Hope that gives you some fresh ideas.

James Edward Gray II
 
L

Li Chen

Hi James,

Thank you very much. But where can I find description about method
row.first and csv.lineno in the document?


Li
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top