0
私はちょうどPythonを起動しています!Pythonのリストまたは辞書をCSVファイルに書く(複数の列を含む行)
私は辞書があり、同じ行のそれ自身の列にそれぞれのメンバーを印刷したい場所にCSVファイルを作成します。
私は辞書の配列を持っているように、私はそれぞれの行がそれらのうちの1つと各行の各列が項目を内部で表現するようにしたいと思います。
import csv
"... we are going to create an array of dictionaries and print them all..."
st_dic = []
true = 1
while true:
dummy = input("Please Enter name, email, mobile, university, major")
x = dummy.split(",")
if "Stop" in x:
break
dict ={"Name":x[0],"Email":x[1],"Mobile":x[2],"University":x[3],"Major":x[4]}
st_dic.append(dict)
f2 = open("data.csv" , "w")
with open("data.csv", "r+") as f:
writer = csv.writer(f)
for item in st_dic:
writer.writerow([item["Name"], item["Email"], item["Mobile"] , item["University"] , item["Major"]])
f.close()
事Iの出力は、今、私はちょうど彼らがその行内で独自の列に、それぞれを区切って最初の辞書のデータを含む行欲しいれます。