0
这可能是一个倒退的方法。我有一些代码读取CSV文件并将结果打印在HTML文件中。如果可能的话,我希望将这个文件打印成无序列表。通过Ruby和CSV打印出多级无序列表
这是我现在有它的输出是不是我想要的:
require 'csv'
col_data = []
CSV.foreach("primary_NAICS_code.txt") {|row| col_data << row}
begin
file = File.open("primary_NAICS_code_html.html", "w")
col_data.each do |row|
indentation, (text,*) = row.slice_before(String).to_a
file.write(indentation.fill("<ul>").join(" ") + "<il>" + text+ "</il></ul?\n")
end
rescue IOError => e
puts e
ensure
file.close unless file == nil
end
输出是什么样的?你想如何看待?如何处理一些示例CSV? “关于您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码以再现问题本身。请参阅http://SSCCE.org以获取指导。” –