[Tutor] Problem with strings

Daniel D. Laskey, CPA dlaskey@laskeycpa.com
Thu, 17 Aug 2000 14:04:14 -0400


Objective:
1)  To read a file called "s8288_ps.txt";
2)  search through the file line by line for the text "Totals for 4I"; and
3)  send the results of the search line by line to a newfile called "junk2.txt"

Code:
# import sys and string
import sys
import string

# open the file
in_file = open("s8288_ps.txt","r")

# create the file you want to export the data to
out_file = open("junk2.txt","w+")

# read each line in the file	
for line in in_file.readlines():
	# grab each line
	if 'Totals for 4I' in line:
		print a
	# write the new file you created to the file "junk2.txt" 
	out_file.write(a)
out_file.close()
in_file.close()

Error message:
Traceback (innermost last):
  File "today4.py", line 15, in ?
    if 'Totals for 4I' in line:
TypeError: string member test needs char left operand

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