Created
January 27, 2012 23:36
-
-
Save xunker/1691595 to your computer and use it in GitHub Desktop.
skip csv lines with errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tmpfile = Tempfile.new('csv_file_with_errors') | |
FasterCSV.open(tmpfile.path, "r", :headers => true) do |output| | |
loop do | |
begin | |
break unless row = output.shift | |
next unless row.field_row? | |
# do your thing here | |
rescue FasterCSV::MalformedCSVError => e | |
# report the error | |
next | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment