forked from rishidhamija/pythoniffie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonglist.py
75 lines (73 loc) · 2.55 KB
/
songlist.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import cPickle as p
liederdatei = 'liederliste.data' # Datei in welche später die Liederliste gespeichert werden soll
class song:
def __init__(self, name, interpret):
self.name = name
self.interpret = interpret
print 'Song will be initialized'
def auskunft(self):
print 'Interpreter: "%s" Title: "%s"' %(self.interpret, self.name)
try: # Der Versuch die Datei zu laden und ...
f = file(liederdatei)
gl = p.load(f)
except: # ...falls sie noch nicht vorhanden ist, die Erstellung
ld = [] # ld steht fuer 'L'ieder'L'iste
f = file(liederdatei, 'w')
p.dump(ld, f)
f.close()
del ld
f = file(liederdatei)
gl = p.load(f)
def menue(): # Das Menue
print 'Welcome to your song list'
print 'Please press..'
print '1 to view your song list'
print '2 to search a song'
print '3 to add a song
print '4 to delete a song from your list'
print '5 to save your list'
print '6 to close the program'
menue()
while True:
print '- - - - - - - - - - - - - - - - - - - - - -' # Aus Schoenheitsgruenden in der IDLE diese Reihe
option = raw_input('Please enter your option: ')
if option == '1':
if len(gl) > 0:
print 'There are %d Lsongs in your list:' % len(gl)
for lied in gl:
lied.auskunft()
else:
print 'IYour list is empty'
elif option == '2':
such_name = raw_input('Please enter the interpreter of the song youre searching for: ')
for lied in gl:
if such_name == lied.name or lied.interpret:
lied.auskunft()
else:
print 'SThis song isnt available!'
elif option == '3':
neu_lied = raw_input('Please enter the name of the song you want to add: ')
neu_interpret = raw_input('Please enter the name of the interpreter: ')
neu_lied = song(neu_lied, neu_interpret)
gl.append(neu_lied)
elif option == '4':
del_name = raw_input('Please enter the name of the song you want to delete: ')
for lied in gl:
if del_name == lied.name:
gl.remove(lied)
print 'Song deleted!'
break
else:
print 'SThe song isnt in your list!'
elif option == '5':
f = file(liederdatei, 'w')
p.dump(gl, f)
f.close()
print 'Saved!'
f = file(liederdatei)
gl = p.load(f)
elif option == '6':
print 'See you soon!'
break
else:
print 'Error! Please enter a number between 1-5'