Hi. Paul.

I could not reproduce your error, but there is a obvious problem.
File open mode "r+" does not create  a file if it is not existing.
This might not be what you want.

Please replace "r+" with "a" (add new lines to the last of a file) and re-t=
ry.


On Fri, Apr 1, 2011 at 4:31 PM, Paul Joyce <pjoyce / whatsthis.ie> wrote:
> Hello there
>
> I am a little frustrated by a simple problem. =A0This 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). =A0However, it will not write to the file opf for some
> reason. =A0I have done this so many times - what am Imissing.
>
> thanks
> p
>
>
> data =3D Array.new
> curr =3D "x"
> colhead =3D "District,Contract No,Contract Status,Tariff,Name,Supply Poin=
t
> 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 =3D File.new("All-Contracts-29-Mar-11.csv","r")
> =A0 =A0 =A0ipf.each_line { |line|
> =A0 =A0 =A0next if line.match(/^$/)
> =A0 =A0 =A0data =3D line.split(",")
> =A0 =A0 =A0if curr =3D=3D "x" =A0 =A0 # =A0Initialize
> =A0 =A0 =A0 =A0puts "Initialize . . " + data[0]
> =A0 =A0 =A0 =A0opf =3D File.new(data[0] + '-feeder-customer.csv',"r+")
> =A0 =A0 =A0 =A0opf.puts colhead =A0 # <----- =A0HERE
> =A0 =A0 =A0end
> =A0 =A0 =A0if curr !=3D data[0] and curr !=3D "x"
> =A0 =A0 =A0 =A0 puts "New File . . . " + data[0]
> =A0 =A0 =A0 =A0 opf.close
> =A0 =A0 =A0 =A0 opf =3D File.new(data[0] + "-feeder-customer.csv","r+")
> =A0 =A0 =A0 =A0 opf.puts colhead
> =A0 =A0 =A0end
> =A0 =A0 =A0opf.puts line
> =A0 =A0 =A0curr =3D data[0]
> =A0 =A0}
> ipf.close;
> opf.close;
>
> puts 'DONE.'
>
> --
> Posted via http://www.ruby-forum.com/.
>
>



--=20
Haruka YAGNI
hyagni / gmail.com