-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_fields.py
More file actions
30 lines (25 loc) · 836 Bytes
/
Copy pathget_fields.py
File metadata and controls
30 lines (25 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def get_fields(filename):
''' Input is a filename
return a list [[motnhs],[days],[names]]
'''
f = open(filename)
line = f.readline() #Skips past first two lines of the file
line = f.readline()
months = []
days = []
names = []
while line.startswith('#'): #Skip past comments
line = f.readline()
while line:
lst = line.strip().split(',') #Split each line into a list
month = lst[0]
day = lst[1]
name = lst[2]
months.append(month) #Add each element of the list into month, day, and name
days.append(day)
names.append(name)
print(month, day, name) #Print each month, day, and name
line = f.readline()
f.close()
return [months, days, names]
result = get_fields('songs.txt')