Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2089

SImple question about file io

From Paul Joyce <pjoyce@whatsthis.ie>
Newsgroups comp.lang.ruby
Subject SImple question about file io
Date 2011-04-01 02:31 -0500
Organization Service de news de lacave.net
Message-ID <2f3b59003ad3466c17243f27510084bf@ruby-forum.com> (permalink)

Show all headers | View raw


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.'

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

SImple question about file io Paul Joyce <pjoyce@whatsthis.ie> - 2011-04-01 02:31 -0500
  Re: SImple question about file io Haruka YAGNI <hyagni@gmail.com> - 2011-04-01 02:50 -0500
  Re: SImple question about file io Haruka YAGNI <hyagni@gmail.com> - 2011-04-01 03:03 -0500
  Re: SImple question about file io Paul Joyce <pjoyce@whatsthis.ie> - 2011-04-01 05:21 -0500
    Re: SImple question about file io Haruka YAGNI <hyagni@gmail.com> - 2011-04-01 06:30 -0500

csiph-web