Hi, I was wondering if someone could help me wrap my head round iterations in a while loop. What I am trying to do is do a word replace and then add a numbering to each replace.
IE
Therapist bl;kja;lafkja;ldkjad;l
Patient ;alkjf;dljkad;ljkfl;kaj;
Therapist bl;kja;lafkja;ldkjad;l
Patient ;alkjf;dljkad;ljkfl;kaj;
To
T1 bl;kja;lafkja;ldkjad;l
P1 ;alkjf;dljkad;ljkfl;kaj;
T2 bl;kja;lafkja;ldkjad;l
P2 ;alkjf;dljkad;ljkfl;kaj;
What I have so far I have borrowed from ghostdog74 ( thank you so much for getting me started). The code below can change the word and iterate the current line but not the individual replaced name. IE Therapist to T1, Patient to P1, Therapist to T2 ect.
Thanks in advance.
Don
#! /usr/bin/env python2.7
import os, sys
count = 0
f = open("header_text.txt")
o = open("Target.txt","a")
name1 = raw_input("Please tell me who the first speaker is: ")
while 1:
line = f.readline()
if not line: break
count = count + 1
nameCount = name1 + str(count)
#print nameCount
line = line.replace("Therapist", nameCount)
o.write(line + "\n")
o.close()