[Tutor] more spliting strings
Daniel D. Laskey, CPA
dlaskey@laskeycpa.com
Mon, 21 Aug 2000 16:20:08 -0400
Dear Tutor:
From the help I received from Remco, Amoreira and Denis, my little =
program searches a text file and gets rid of the lines with 'Total' in =
it and only reads the lines with a '$' in it.
Now I have to split this file up, but the file doesn't have any comma or =
tab deliminators. It is a fixed length delimated file.
I only want the first 6 characters and the last 13 characters. Then I =
want to add a date to the file in the first position.
# ----------------------------------------
# import sys and string
import sys
import string
# print the following statement
print "Enter the name of the datafile file to convert:"
# ask the name of the data_file to use
data_file =3D raw_input('File name to process? ')
# read the data_file and put it into a file called in_file
in_file =3D open(data_file,"r")
# create the file to export the data to
out_file =3D open("junk.txt","w+")
# read the file in_file line by line
lines =3D in_file.readlines()
# keep the list of lines=20
resultlines =3D []
# search through each line of the file
for line in lines:
# search for lines with 'Total' in it
if string.find(line,'Total') >-1:
# move on and skip this line
continue=09
if string.find(line,'$') >-1:
# keep the line
resultlines.append(line)
# # end of processFile() function #
# How do I get the program to read the data from the process
# above and the perform the string manipulation I need?
a =3D ['08/18/00']
good_data =3D a + "," + line[:6] + "," + line[-13:]
# write the results to the new file
out_file.writelines(good_data)
#out_file.write(good_data)
out_file.close()
in_file.close()
# ----------------------------------------
#Traceback (innermost last):
# File "today7.py", line 36, in ?
# good_data =3D a + "," + line[:6] + "," + line[-13:]
#TypeError: illegal argument type for built-in operation
Thanks,
Dan
-------------------------------------------------------------------------=
--------------
| Daniel D. Laskey, CPA-------------------dlaskey@laskeycpa.com
| Daniel D. Laskey Company, P.C.------231-723-8305 Voice
| =
231-723-6097 Fax
| Certified Public Accountants
| 507 Water Street
| Manistee, MI 49660
-------------------------------------------------------------------------=
--------------