是相當新的編程和我需要一種方法來從一個函數中增加了輸入數據,並把它添加到CSV文件中如何添加到CSV文件,從不同的功能在Python
def songlists():
with open('songs.csv') as csvfile:
songs = csv.reader(csvfile, delimiter = ',')
x = [row for row in songs]
return x
def menu(x):
print("Songs to Learn 1.0 - ")
songlists()
print(len(x), "songs in list")
print("""Menu :
L - List songs
A - Add new song
C - Complete a song
Q - Quit""")
menuChoice = str(input('>>>'))
while menuChoice != "q":
if menuChoice == "l":
songlists()
i = 0
for row in x:
name, artist, year, learnt = row
print(str(i),'.', learnt, name, artist, "(", year, ")")
i += 1
elif menuChoice == "a":
songlists()
#want to be able to add to the csv file from here and be able to add the new name artists and year etc
#print("??")
elif menuChoice == "c":
print("???")
else:
print("Invalid choice, Choose again")
print("""Menu :
L - List songs
A - Add new song
C - Complete a song
Q - Quit""")
menuChoice = str(input('>>>'))
什麼我想要做的是用戶在功能菜單()中輸入「a」,它會提示他們添加名稱和藝術家等,然後將其添加到歌曲列表功能中打開的csv文件中。 對不起,如果這個問題格式不正確。 謝謝