Thread: Reading a file
View Single Post
Old 05-11-2006, 05:55 AM   #22 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
I found an easier way to understand how dis work

but it dont work fully

Code:
def formate(datafile):
	returnlines = ""
	currentline = datafile.readline()
	while currentline:
		if currentline[0] != ('#'):
			returnlines+= currentline +'\n'
			currentline = datafile.readline()
			return returnlines



def listdata(filename):
	datafile = open(filename, 'r')
	returnlines = []
	for currentline in datafile.readlines():
		if not currentline.startswith('#'):
			returnlines.append(currentline.replace('\n', '').split(','))
			currentline = datafile.readline()
			datafile.close()
			return returnlines


def presentdata(showdata):
	for item in showdata:
		print item
		print '\n'
to exercute the code

>>>datafile = open("StudentList.txt", "r")
>>>eventdata = datafile.readlines()
>>>print eventdata
coolman is offline   Reply With Quote