Q
Q
qwe456r2019-08-01 16:21:20
ruby
qwe456r, 2019-08-01 16:21:20

How to create a csv file, at the same time set headers for it, then add information there?

This is how it looks like:
5d42e6b79ba3c945087182.png
How to create a csv file, at the same time set headers for it, which will not change in the future and will not be rewritten after going through the cycle and throwing information into the file?

#пробовал делать вот так, но Name и Price 
#записываются еще раз после того как нужная инфа запишется и 
#будет осуществлен дальшейний сбор инфы (Смотреть СКРИН)
CSV.open(output_file+".csv", "a") do |csv|
  csv << ['Name ;Price']	#		
  #собирается различная информацию	
  #...
  #	
  csv <<  ["#{Name}; #{Price}"] #происходит запись в файл					
end

Maybe you can first create a file, write a header there, and after that
CSV.open(output_file+".csv", "a") do |csv|

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Blokhin, 2019-08-01
@TITnet

https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question