How write into CSV file properly

后端 未结 2 1204
温柔的废话
温柔的废话 2021-02-19 05:15

i am using ruby 1.9.2 and also use its csv library.I want to write in csv properly just

like this

name,country_code,destination,code
Afghanistan,93,Bama         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 05:30

    I think general CSV writer will be good enough for you:

    require 'csv'
    file = "my_file.csv"
    CSV.open( file, 'w' ) do |writer|
      @coun.each do |c|
        writer << [c.name, c.country_code, c.user_id, c.subscriber_id]
      end
    end
    

提交回复
热议问题