[Tutor] Strings and file saving

Daniel D. Laskey, CPA dlaskey@laskeycpa.com
Fri, 18 Aug 2000 14:50:26 -0400


HEY YOU GUYS!!

Objective: 
1)  Read this ASCII file that is space deliminated;
2)  Pull out only the lines that have a '$' characters in the line;
3)  Save the data to a new file.

#  ----------- Code -----------  
# import sys and string
import sys
import string

# get the appropriate data file
in_file = open("data_file","r")

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

# read each line in the file	
for line in in_file.readlines():
	if string.find(line,'$')>= 0:
#		# "print line" works well
#		#print line
		a = line
#	# write the new file you created to the file "junk2.txt" 
	out_file.write(a)
out_file.close()
in_file.close()
#  ----------- End of Code --------------

Traceback (innermost last):
  File "today6.py", line 19, in ?
    out_file.write(a)
NameError: a

I think I am a classic case of PDD ... Python Deficit Disorder :).
At best I'm one of those slow learners, so bear with me, please.

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