How write into CSV file properly

后端 未结 2 1202
温柔的废话
温柔的废话 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:26
    csv << "\n"
    

    Stackoverflow requires 30 characters in an answer, but I don't know what more to say.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题