[Tutor] Printing to file on one line

Peter Brown peterabrown at froggy.com.au
Wed Sep 24 08:43:01 EDT 2003


  Jeff,

Thanks for your good work. The example you gave works well for Windows
but not Linux.

The example I sent yesterday was from Redhat 9. The output below shows
outputting 82 characters, but the line is still wrapped note '\n' on
first line (after payments). How did that \n get there? My programme
didn't include it, is it a bug in Python on Redhat 9 - Python 2.2.2?
Secondly, the date has two spaces preceeding it, but no formatting to
accomplish this?

TIA

Peter

def write_header(aba_file,
batchtype,conf_name,conf_apca,conf_desc,smdate):
    batchname = '%02sMET' % batchtype
    format = '%-18s%-12s%-26s%-6s%-12s%6s\r\n'
    output = format % ('0', batchname, conf_name, str(conf_apca[:6]),  
conf_desc, smdate)
    aba_file.write(output)
    print "Outputting %d bytes to file" % len(output)
    print output

Outputting 82 bytes to file
0                 68PET       PA Exports                 239381Payments
  240903

 print repr(open('/usr/TP/20030924.aba', 'rb').read(82))
'0                 68PET       PA Exports                
239381Payments\n  240903\r\n'





More information about the Tutor mailing list