#read lines from file
fobj = open('record.txt', 'r+')
print 'opened file: ', fobj.name
all_lines = fobj.readlines()
fobj.close()
lines = [l[:-1].split(', ') for l in all_lines if not l.startswith('#') and l.strip()]
#list person who's score less than 60
print [s[0] for s in lines if int(s[2]) < 60]
#list person who's name starts with 'L'
print [s[0] for s in lines if s[0].startswith('L')]
#compute the score of all person
print sum([int(s[2]) for s in lines])
#write new lines contains capitalize name into file
fobj = open('record2.txt', 'w+')
print 'opend file: ', fobj.name
newlines = []
for line in all_lines:
if line[0].islower():
line = line.capitalize()
newlines.append(line)
print newlines
if newlines:
fobj.writelines(newlines)
fobj.close()