【发布时间】:2017-08-28 06:42:23
【问题描述】:
我是编程新手,需要一种方法来从一个函数添加输入数据并将其添加到 csv 文件中
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('>>>'))
我想做的是用户在功能 menu() 中输入“a”,它会提示他们添加名称和艺术家等,然后将其添加到在歌曲列表功能中打开的 csv 文件中. 抱歉,如果这个问题的格式不正确。 谢谢
【问题讨论】:
标签: python-3.x csv export-to-csv