0

我有以下 Ruby 代码:

require 'octokit.rb'
require 'csv.rb'

CSV.foreach("actors.csv") do |row|
  CSV.open("node_attributes.csv", "wb") do |csv|
    csv << [Octokit.user "userid"]
  end
end
  • 我有一个名为的 csv actors.csv,其中每一行都有一个条目 - 一个带有用户 ID 的字符串。
  • 我想遍历所有行,并为每一行做Octokit.user "userid",然后将每个查询的输出存储在 CSV - 的单独行中node_attributes.csv

我的代码似乎没有这样做?如何修改它以使其正常工作?

4

1 回答 1

1
require 'csv'
DOC = 'actors.csv'
DOD = 'new_output.csv'
holder = CSV.read(DOC)

您可以通过调用导航它

holder[0][0]
=> data in the array 
holder[1][0] 
=> moar data in array

说得通?

#make this a loop
profile = []
profile[0] = holder[0][0]
profile[1] = holder[1][0]
profile[2] = 'whatever it is you want to store in the new cell'

CSV.open(DOD, "a") do |data|
data << profile.map
end

#end the loop here

最后一段代码会将您想要的任何内容打印到新的 csv 文件中

于 2013-07-25T18:24:49.760 回答