T
Todd_Calhoun
I'm trying to learn about text processing in Python, and I'm trying to
tackle what should be a simple task.
I have long text files of books with a citation between each paragraph,
which might be like "Bill D. Smith, History through the Ages, p.5".
So, I need to search for every line that starts with a certain string (in
this example, "Bill D. Smith"), and delete the whole line.
I've tried a couple of different things, but none seem to work. Here's my
latest try. I apologize in advance for being so clueless.
##########################
#Text search and delete line tool
theInFile = open("test_f.txt", "r")
theOutFile = open("test_f_out.txt", "w")
allLines = theInFile.readlines()
for line in allLines:
if line[3] == 'Bill':
line == ' '
theOutFile.writelines(allLines)
#########################
I know I could do it in Word fairly easily, but I'd like to learn the Python
way to do things.
Thanks for any advice.
tackle what should be a simple task.
I have long text files of books with a citation between each paragraph,
which might be like "Bill D. Smith, History through the Ages, p.5".
So, I need to search for every line that starts with a certain string (in
this example, "Bill D. Smith"), and delete the whole line.
I've tried a couple of different things, but none seem to work. Here's my
latest try. I apologize in advance for being so clueless.
##########################
#Text search and delete line tool
theInFile = open("test_f.txt", "r")
theOutFile = open("test_f_out.txt", "w")
allLines = theInFile.readlines()
for line in allLines:
if line[3] == 'Bill':
line == ' '
theOutFile.writelines(allLines)
#########################
I know I could do it in Word fairly easily, but I'd like to learn the Python
way to do things.
Thanks for any advice.