Thread: Reading a file
View Single Post
Old 05-04-2006, 04:34 AM   #14 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
it dont work fully

current data

NUM |FIRSTNAME| SURNAME |course |
------------------------------------------
12400 ERIC RONNEY CS
------------------------------------------
12500 MICHAEL OWEN CS
------------------------------------------
12600 SCOT MAN CS
------------------------------------------
12700 GEOGE YO IT
------------------------------------------

Code:
import re
returnline = []
f = open("List.txt", "r")
 for line in f.readlines():
	returnline.append(re.compile(' ').sub(',', line[0:-1]))
	for item in returnline:
		print item
new data after the program is excutered

Code:
NUM,,,|FIRSTNAME|,SURNAME,|course,|
NUM,,,|FIRSTNAME|,SURNAMENAME,|course,|
------------------------------------------
NUM,,,|FIRSTNAME|,SECONDNAME,|course,|
------------------------------------------
12400	ERIC		ROONEY	CS

NUM,,,|FIRSTNAME|,SURNAME,|course,|
------------------------------------------
12400	ERIC		ROONEY	CS
------------------------------------------
NUM,,,|FIRSTNAME|,SURNAME,|course,|
------------------------------------------
12400	ERIC		ROONEY	CS
------------------------------------------
12500	MICHAEL		OWEN	CS
NUM,,,|FIRSTNAME|,SURNAME,|course,|
------------------------------------------
and the program just rans forever and it dont stop
coolman is offline   Reply With Quote