Thread: Reading a file
View Single Post
Old 05-01-2006, 10:23 AM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Look at the split section That might help you a bit.
Here is a fast inplementation of it, it's not ideal, but it will give you a hint..
Code:
#!/usr/bin/python
import re                      # make regular expression available
list = []
f = open("Studentlist.txt", "r") # open file
lines = f.readlines()          # make every line available
for line in lines:	       # loop through lines
    if not re.match("^-", line): # if line dosn't start with '-'
          list.append(re.split('[\W]+', line[0:-1]))# add splitted line 
del list[0]                    # remove the first line "ID | etc "
for item in list:
    if len(item):
        print "--------------------------------"
        print "Student ID:\t", item[0]
        print "Student Name:\t", item[1], item[2]
        print "Student Class:\t", item[-1]
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote