記錄#
- 今天沒有知識點學習,只有編碼練習。
- 編寫一個超級綜合的程式,在本地讀取寫入音樂資訊。
- 今天的編程大體還算順利,只是記錯了 csv.DictReader 和 csv.Reader。只有 DictReader 讀取之後才是字典形式。
CODE#
import csv, os
print("artist")
with open("100MostStreamedSongs.csv", "r") as file:
reader = csv.DictReader(file)
folder = os.listdir()
for row in reader:
if row['Artist(s)'] not in folder:
os.mkdir(row['Artist(s)'])
pathname = f"{row['Artist(s)']}/{row['Song']}.txt"
with open(pathname, "w") as f:
f.write(pathname)
print("done!")