[Tutor] Another string question
Jay Mutter III
jmutter at uakron.edu
Thu Mar 22 21:44:01 CET 2007
I wanted the following to check each line and if it ends in a right
parentheses then write the entire line to one file and if not then
write the line to anther.
It wrote all of the ) to one file and the rest of the line (ie minus
the ) to the other file.
in_filename = raw_input('What is the COMPLETE name of the file you
would like to process? ')
in_file = open(in_filename, 'rU')
text = in_file.read()
count = len(text.splitlines())
print "There are ", count, 'lines to process in this file'
out_filename1 = raw_input('What is the COMPLETE name of the file in
which you would like to save Companies? ')
companies = open(out_filename1, 'aU')
out_filename2 = raw_input('What is the COMPLETE name of the file in
which you would like to save Inventors? ')
patentdata = open(out_filename2, 'aU')
for line in text:
if line[-1] in ')':
companies.write(line)
else:
patentdata.write(line)
in_file.close()
companies.close()
patentdata.close()
Thanks
jay
More information about the Tutor
mailing list