P
Paul Joyce
Hello there
I am a little frustrated by a simple problem. This the script below is
failing with
C:/projects/LAF-01/For-District-Managers/breakout.rb:23:in `block in
<main>': wrong argument type Object (expected Data) (TypeError)
This script simple breaks a large file into smaller ones byu the first
column (District). However, it will not write to the file opf for some
reason. I have done this so many times - what am Imissing.
thanks
p
data = Array.new
curr = "x"
colhead = "District,Contract No,Contract Status,Tariff,Name,Supply Point
No,Meter No,Meter Make,Address 1,Address 2,Address 3,Address 4,ICS
Feeder Information,Feeder Name,Feeder Meter No,Comments"
#puts template
ipf = File.new("All-Contracts-29-Mar-11.csv","r")
ipf.each_line { |line|
next if line.match(/^$/)
data = line.split(",")
if curr == "x" # Initialize
puts "Initialize . . " + data[0]
opf = File.new(data[0] + '-feeder-customer.csv',"r+")
opf.puts colhead # <----- HERE
end
if curr != data[0] and curr != "x"
puts "New File . . . " + data[0]
opf.close
opf = File.new(data[0] + "-feeder-customer.csv","r+")
opf.puts colhead
end
opf.puts line
curr = data[0]
}
ipf.close;
opf.close;
puts 'DONE.'
I am a little frustrated by a simple problem. This the script below is
failing with
C:/projects/LAF-01/For-District-Managers/breakout.rb:23:in `block in
<main>': wrong argument type Object (expected Data) (TypeError)
This script simple breaks a large file into smaller ones byu the first
column (District). However, it will not write to the file opf for some
reason. I have done this so many times - what am Imissing.
thanks
p
data = Array.new
curr = "x"
colhead = "District,Contract No,Contract Status,Tariff,Name,Supply Point
No,Meter No,Meter Make,Address 1,Address 2,Address 3,Address 4,ICS
Feeder Information,Feeder Name,Feeder Meter No,Comments"
#puts template
ipf = File.new("All-Contracts-29-Mar-11.csv","r")
ipf.each_line { |line|
next if line.match(/^$/)
data = line.split(",")
if curr == "x" # Initialize
puts "Initialize . . " + data[0]
opf = File.new(data[0] + '-feeder-customer.csv',"r+")
opf.puts colhead # <----- HERE
end
if curr != data[0] and curr != "x"
puts "New File . . . " + data[0]
opf.close
opf = File.new(data[0] + "-feeder-customer.csv","r+")
opf.puts colhead
end
opf.puts line
curr = data[0]
}
ipf.close;
opf.close;
puts 'DONE.'