質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CSV

CSV(Comma-Separated Values)はコンマで区切られた明白なテキスト値のリストです。もしくは、そのフォーマットでひとつ以上のリストを含むファイルを指します。

Tkinter

Tkinterは、GUIツールキットである“Tk”をPythonから利用できるようにした標準ライブラリである。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

4289閲覧

GUIにて作成した内容をCSV形式にて、保存、読み込みを行いたい

fuji36_om

総合スコア8

CSV

CSV(Comma-Separated Values)はコンマで区切られた明白なテキスト値のリストです。もしくは、そのフォーマットでひとつ以上のリストを含むファイルを指します。

Tkinter

Tkinterは、GUIツールキットである“Tk”をPythonから利用できるようにした標準ライブラリである。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/09/02 01:05

前提・実現したいこと

作成したプログラムで、No.氏名、性別、生年月日を入力した後、
CSV形式にて保存したい。
CSV形式で保存した内容を読み込む機能を付けたい。
具体的には、各リストの内容を行ごとに保存し、読み込む際は逆にプログラム内の
リストに上書きする方法を取りたいです。

発生している問題・エラーメッセージ

試しに保存してみたが、CSV形式ではなさそう…。
読み込みの関数は、手入力したものを用意して試しましたが、エラーしか起こさなかったので削除しています。

該当のソースコード

python

1#tkinterのインポート 2import tkinter as tk 3from tkinter import messagebox 4from dateutil.parser import parse 5 6# ウィンドウを作成 7root = tk.Tk() 8root.title("Hello, World!") # タイトル 9root.geometry("500x300") # サイズ 10 11b = tk.Label(text="コントロール画面")# 文字の出力 12b.pack() 13 14 15#全Entry消去 16def clear(): 17 txt_No11.delete(0, tk.END) 18 txt_No12.delete(0, tk.END) 19 txt_No13.delete(0, tk.END) 20 txt_No21.delete(0, tk.END) 21 txt_No22.delete(0, tk.END) 22 txt_No23.delete(0, tk.END) 23 txt_No31.delete(0, tk.END) 24 txt_No32.delete(0, tk.END) 25 txt_No33.delete(0, tk.END) 26 txt_No41.delete(0, tk.END) 27 txt_No42.delete(0, tk.END) 28 txt_No43.delete(0, tk.END) 29 txt_No51.delete(0, tk.END) 30 txt_No52.delete(0, tk.END) 31 txt_No53.delete(0, tk.END) 32 33#手入力で編集された全Entryを一時的に記憶 34def Memory(index): 35 print( " No11 {} Len:{}".format(index,len(no))) 36 no[index] = txt_No11.get() 37[index] = txt_No21.get() 38[index] = txt_No31.get() 39 性別[index] = txt_No41.get() 40 生年月日[index] = txt_No51.get() 41 index+=1 42 print( " No12 {} Len:{}".format(index,len(no))) 43 if( index >= len(no)) : return 44 no[index] = txt_No12.get() 45[index] = txt_No22.get() 46[index] = txt_No32.get() 47 性別[index] = txt_No42.get() 48 生年月日[index] = txt_No52.get() 49 index+=1 50 print( " No13 {} Len:{}".format(index,len(no))) 51 if( index >= len(no)) : return 52 no[index] = txt_No13.get() 53[index] = txt_No23.get() 54[index] = txt_No33.get() 55 性別[index] = txt_No43.get() 56 生年月日[index] = txt_No53.get() 57 58#移動した先のページ内容を全Entryに再表示する 59def hyoji(index): 60 txt_No11.insert(tk.END,no[index]) 61 txt_No21.insert(tk.END,[index]) 62 txt_No31.insert(tk.END,[index]) 63 txt_No41.insert(tk.END,性別[index]) 64 txt_No51.insert(tk.END,生年月日[index]) 65 66 index +=1 67 #print('index:', index)#確認用 68 if( index >= len(no)) : return 69 txt_No12.insert(tk.END,no[index]) 70 txt_No22.insert(tk.END,[index]) 71 txt_No32.insert(tk.END,[index]) 72 txt_No42.insert(tk.END,性別[index]) 73 txt_No52.insert(tk.END,生年月日[index]) 74 75 index +=1 76 #print('index:', index)#確認用 77 if( index >= len(no)) : return 78 txt_No13.insert(tk.END,no[index]) 79 txt_No23.insert(tk.END,[index]) 80 txt_No33.insert(tk.END,[index]) 81 txt_No43.insert(tk.END,性別[index]) 82 txt_No53.insert(tk.END,生年月日[index]) 83 84 85#(各ボタン用関数) 86#前ボタン_前ページに移る 87def btn_prev(): 88 global pageid 89 Memory(pageid) 90 if pageid-3 <0: 91 messagebox.showerror('エラー', 'これ以上は前に戻れません') 92 print("これ以上は前に戻れません") 93 return 94 if check_content(): 95 return 96 clear() 97 pageid-=3 98 hyoji(pageid) 99 100 101#次ボタン_次ページに移る 102def btn_next(): 103 global pageid 104 nextId = pageid+3 105 Memory(pageid) 106 if check_content(): 107 return 108 if(nextId) >= len(no): 109 messagebox.showerror('エラー', 'これ以上は先に進めません') 110 print("これ以上は先に進めません") 111 return 112 clear() 113 pageid+=3 114 hyoji(pageid) 115 116 117#クリアボタン_内容を消去 118def btn_clear(): 119 clear() 120 121#チェックボタン_内容をチェック 122def check_content(): 123 global pageid 124 s=error_check1(pageid) 125 errmsg = error_check2(pageid) 126 if len(errmsg) > 0: 127 if len(s) > 0: 128 s += "\n" 129 s += errmsg 130 errmsg = error_check3(pageid) 131 if len(errmsg) > 0: 132 if len(s) > 0: 133 s += "\n" 134 s += errmsg 135 errmsg = error_check4(pageid) 136 if len(errmsg) > 0: 137 if len(s) > 0: 138 s += "\n" 139 s += errmsg 140 errmsg = error_check5(pageid) 141 if len(errmsg) > 0: 142 if len(s) > 0: 143 s += "\n" 144 s += errmsg 145 146 if len(s) > 0: 147 print("[" + s + "]") 148 messagebox.showerror('エラー', s) 149 return True 150 return False 151 152#noのチェックを行う 153def error_check1(index): 154 s = "" 155 for j in range(3): 156 i = index + j 157 if(no[i].isdecimal()) == True: 158 pass 159 else: 160 if len(s) > 0: 161 s += "\n" 162 s += "{}列目の「No」に整数を入れてください".format(j+1) 163 return s 164 165#姓のチェックを行う 166def error_check2(index): 167 s = "" 168 for j in range(3): 169 i = index + j 170 if([i].isalpha()) == True: 171 pass 172 else: 173 if len(s) > 0: 174 s += "\n" 175 s += "{}列目の「姓」に正しく記入してください".format(j+1) 176 return s 177 178def error_check3(index): 179 s = "" 180 for j in range(3): 181 i = index + j 182 if([i].isalpha()) == True: 183 pass 184 else: 185 if len(s) > 0: 186 s += "\n" 187 s += "{}列目の「名」に正しく記入してください".format(j+1) 188 return s 189 190def error_check4(index): 191 s = "" 192 for j in range(3): 193 i = index + j 194 if(性別[i]) == "男" or (性別[i]) == "女": 195 pass 196 else: 197 if len(s) > 0: 198 s += "\n" 199 s += "{}列目の「性別」に男または女で記入してください".format(j+1) 200 return s 201 202#生年月日を入力しているか確認するための関数is_date 203#error_check5に内蔵 204def is_date(string, fuzzy=False): 205 try: 206 parse(string)#parse関数が重要 207 return True 208 209 except ValueError: 210 return False 211 212def error_check5(index): 213 s = "" 214 for j in range(3): 215 i = index + j 216 if is_date(生年月日[i]) == True: 217 pass 218 else: 219 if len(s) > 0: 220 s += "\n" 221 s += "{}列目の「生年月日」に正しく記入してください".format(j+1) 222 return s 223 224#保存 225def btn_save(): 226 with open('test.csv', mode='w') as file: 227 #for num in range(4): 228 file.write(str(no) + "\n") 229 file.write(str() + "\n") 230 file.write(str() + "\n") 231 file.write(str(性別) + "\n") 232 file.write(str(生年月日) + "\n") 233 Next_button 234 235# 各種ボタン設定 236Prev_button = tk.Button(root,text='前ボタン',command = btn_prev).place(width=50,x=330,y=250) 237Next_button = tk.Button(root,text='次ボタン',command = btn_next).place(width=50,x=380,y=250) 238Clear_button = tk.Button(root,text='クリア',command = btn_clear).place(width=50,x=25,y=250) 239Read_button = tk.Button(root,text='読込').place(width=50,x=130,y=250) 240Save_button = tk.Button(root,text='保存',command = btn_save).place(width=50,x=180,y=250) 241 242 243# テキスト注釈を表示 244lbl_1 = tk.Label(text='No.') 245lbl_1.place(x=30, y=50) 246 247lbl_2 = tk.Label(text='姓') 248lbl_2.place(x=110, y=50) 249 250lbl_3 = tk.Label(text='名') 251lbl_3.place(x=220, y=50) 252 253lbl_4 = tk.Label(text='性別') 254lbl_4.place(x=330, y=50) 255 256lbl_5 = tk.Label(text='生年月日') 257lbl_5.place(x=400, y=50) 258 259# テキストボックス1(No) 260txt_No11 = tk.Entry(width=8) 261txt_No11.place(x=30, y=80) 262 263txt_No12 = tk.Entry(width=8) 264txt_No12.place(x=30, y=110) 265 266txt_No13 = tk.Entry(width=8) 267txt_No13.place(x=30, y=140) 268 269 270# テキストボックス2(姓) 271txt_No21 = tk.Entry(width=12) 272txt_No21.place(x=110, y=80) 273 274txt_No22 = tk.Entry(width=12) 275txt_No22.place(x=110, y=110) 276 277txt_No23 = tk.Entry(width=12) 278txt_No23.place(x=110, y=140) 279 280 281# テキストボックス3(名前) 282txt_No31 = tk.Entry(width=12) 283txt_No31.place(x=220, y=80) 284 285txt_No32 = tk.Entry(width=12) 286txt_No32.place(x=220, y=110) 287 288txt_No33 = tk.Entry(width=12) 289txt_No33.place(x=220, y=140) 290 291 292# テキストボックス4(性別) 293txt_No41 = tk.Entry(width=8) 294txt_No41.place(x=330, y=80) 295 296txt_No42 = tk.Entry(width=8) 297txt_No42.place(x=330, y=110) 298 299txt_No43 = tk.Entry(width=8) 300txt_No43.place(x=330, y=140) 301 302 303# テキストボックス5(生年月日) 304txt_No51 = tk.Entry(width=12) 305txt_No51.place(x=400, y=80) 306 307txt_No52 = tk.Entry(width=12) 308txt_No52.place(x=400, y=110) 309 310txt_No53 = tk.Entry(width=12) 311txt_No53.place(x=400, y=140) 312 313no = ["1","に","3","4","5","6","7","8","9","10","11"] 314= ["渡邊","柳川","清野","根本","阿部","稲田","木内","三宅","石村","本郷","山田"] 315= ["沙樹","和臣","菜緒","駿斗","亜依","和徳","喜雄","美南","比呂","香帆","比呂"] 316性別 = ["女","男","女","男","女","男","男","女","男","女","男","女","男"] 317生年月日 = ["1988/07/15","1966/09/04","1979/06/08","1992/03/14","1977/04/04", 318 "1963/11/06","1972/08/21","1992/11/30","1967/12/07","1965/03/20","1977/04/04"] 319pageid = 0 320pageid = 0 321hyoji(pageid) 322 323root.mainloop( ) 324 325

試したこと

各種リストを保存してみたが、保存方法が誤っているのはわかるが、どう記述すべきか、
わからない。
読み込みに至っては見当もつかない。

使用法

クリアボタン・・・全エントリー内の内容を消去する
読み込み  ・・・CSV形式で書かれたファイルを読み込み、リストを上書きする予定
保存    ・・・上書きされたリストを読み込み、CSV形式でファイル書く予定
前ボタン、次ボタン  ・・・ページをめくる機能

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

自己解決しました
曲りなりにも動くようになりました。

python

1#tkinterのインポート 2import tkinter as tk 3from tkinter import messagebox 4from dateutil.parser import parse 5import pandas as pd 6# ウィンドウを作成 7root = tk.Tk() 8root.title("Hello, World!") # タイトル 9root.geometry("500x300") # サイズ 10 11b = tk.Label(text="コントロール画面")# 文字の出力 12b.pack() 13 14#全Entry消去 15def clear(): 16 txt_No11.delete(0, tk.END) 17 txt_No12.delete(0, tk.END) 18 txt_No13.delete(0, tk.END) 19 txt_No21.delete(0, tk.END) 20 txt_No22.delete(0, tk.END) 21 txt_No23.delete(0, tk.END) 22 txt_No31.delete(0, tk.END) 23 txt_No32.delete(0, tk.END) 24 txt_No33.delete(0, tk.END) 25 txt_No41.delete(0, tk.END) 26 txt_No42.delete(0, tk.END) 27 txt_No43.delete(0, tk.END) 28 txt_No51.delete(0, tk.END) 29 txt_No52.delete(0, tk.END) 30 txt_No53.delete(0, tk.END) 31 32#手入力で編集された全Entryを一時的に記憶 33def Memory(index): 34 print( " No11 {} Len:{}".format(index,len(no))) 35 no[index] = txt_No11.get() 36[index] = txt_No21.get() 37[index] = txt_No31.get() 38 性別[index] = txt_No41.get() 39 生年月日[index] = txt_No51.get() 40 index+=1 41 print( " No12 {} Len:{}".format(index,len(no))) 42 if( index >= len(no)) : return 43 no[index] = txt_No12.get() 44[index] = txt_No22.get() 45[index] = txt_No32.get() 46 性別[index] = txt_No42.get() 47 生年月日[index] = txt_No52.get() 48 index+=1 49 print( " No13 {} Len:{}".format(index,len(no))) 50 if( index >= len(no)) : return 51 no[index] = txt_No13.get() 52[index] = txt_No23.get() 53[index] = txt_No33.get() 54 性別[index] = txt_No43.get() 55 生年月日[index] = txt_No53.get() 56 57#移動した先のページ内容を全Entryに再表示する 58def hyoji(index): 59 txt_No11.insert(tk.END,no[index]) 60 txt_No21.insert(tk.END,[index]) 61 txt_No31.insert(tk.END,[index]) 62 txt_No41.insert(tk.END,性別[index]) 63 txt_No51.insert(tk.END,生年月日[index]) 64 65 index +=1 66 #print('index:', index)#確認用 67 if( index >= len(no)) : return 68 txt_No12.insert(tk.END,no[index]) 69 txt_No22.insert(tk.END,[index]) 70 txt_No32.insert(tk.END,[index]) 71 txt_No42.insert(tk.END,性別[index]) 72 txt_No52.insert(tk.END,生年月日[index]) 73 74 index +=1 75 #print('index:', index)#確認用 76 if( index >= len(no)) : return 77 txt_No13.insert(tk.END,no[index]) 78 txt_No23.insert(tk.END,[index]) 79 txt_No33.insert(tk.END,[index]) 80 txt_No43.insert(tk.END,性別[index]) 81 txt_No53.insert(tk.END,生年月日[index]) 82 83 84#(各ボタン用関数) 85#前ボタン_前ページに移る 86def btn_prev(): 87 global pageid 88 Memory(pageid) 89 if pageid-3 <0: 90 messagebox.showerror('エラー', 'これ以上は前に戻れません') 91 print("これ以上は前に戻れません") 92 return 93 if check_content(): 94 return 95 clear() 96 pageid-=3 97 hyoji(pageid) 98 99 100#次ボタン_次ページに移る 101def btn_next(): 102 global pageid 103 nextId = pageid+3 104 Memory(pageid) 105 if check_content(): 106 return 107 if(nextId) >= len(no): 108 messagebox.showerror('エラー', 'これ以上は先に進めません') 109 print("これ以上は先に進めません") 110 return 111 clear() 112 pageid+=3 113 hyoji(pageid) 114 115 116#クリアボタン_内容を消去 117def btn_clear(): 118 clear() 119 120#チェックボタン_内容をチェック 121def check_content(): 122 global pageid 123 s=error_check1(pageid) 124 errmsg = error_check2(pageid) 125 if len(errmsg) > 0: 126 if len(s) > 0: 127 s += "\n" 128 s += errmsg 129 errmsg = error_check3(pageid) 130 if len(errmsg) > 0: 131 if len(s) > 0: 132 s += "\n" 133 s += errmsg 134 errmsg = error_check4(pageid) 135 if len(errmsg) > 0: 136 if len(s) > 0: 137 s += "\n" 138 s += errmsg 139 errmsg = error_check5(pageid) 140 if len(errmsg) > 0: 141 if len(s) > 0: 142 s += "\n" 143 s += errmsg 144 145 if len(s) > 0: 146 print("[" + s + "]") 147 messagebox.showerror('エラー', s) 148 return True 149 return False 150 151#noのチェックを行う 152def error_check1(index): 153 s = "" 154 for j in range(3): 155 i = index + j 156 if(no[i].isdecimal()) == True: 157 pass 158 else: 159 if len(s) > 0: 160 s += "\n" 161 s += "{}列目の「No」に整数を入れてください".format(j+1) 162 return s 163 164#姓のチェックを行う 165def error_check2(index): 166 s = "" 167 for j in range(3): 168 i = index + j 169 if([i].isalpha()) == True: 170 pass 171 else: 172 if len(s) > 0: 173 s += "\n" 174 s += "{}列目の「姓」に正しく記入してください".format(j+1) 175 return s 176 177def error_check3(index): 178 s = "" 179 for j in range(3): 180 i = index + j 181 if([i].isalpha()) == True: 182 pass 183 else: 184 if len(s) > 0: 185 s += "\n" 186 s += "{}列目の「名」に正しく記入してください".format(j+1) 187 return s 188 189def error_check4(index): 190 s = "" 191 for j in range(3): 192 i = index + j 193 if(性別[i]) == "男" or (性別[i]) == "女": 194 pass 195 else: 196 if len(s) > 0: 197 s += "\n" 198 s += "{}列目の「性別」に男または女で記入してください".format(j+1) 199 return s 200 201#生年月日を入力しているか確認するための関数is_date 202#error_check5に内蔵 203def is_date(string, fuzzy=False): 204 try: 205 parse(string)#parse関数が重要 206 return True 207 208 except ValueError: 209 return False 210 211def error_check5(index): 212 s = "" 213 for j in range(3): 214 i = index + j 215 if is_date(生年月日[i]) == True: 216 pass 217 else: 218 if len(s) > 0: 219 s += "\n" 220 s += "{}列目の「生年月日」に正しく記入してください".format(j+1) 221 return s 222 223#保存 224def btn_save(): 225 with open('test.csv', mode='w') as file: 226 file.write("no,姓,名,性別,生年月日\n") 227 for index in range(len(no)): 228 s = no[index] + "," +[index] + "," + \ 229[index] + "," + 性別[index] + "," + 生年月日[index] + "\n" 230 file.write(s) 231#読み込み 232def btn_read(): 233 df = pd.read_csv('test2.csv', encoding='shift_jis',header=None) 234 235 no.clear() 236 for i in range(12): 237 no.append(df.iloc[i, 0]) 238 239.clear() 240 for i in range(12): 241.append(df.iloc[i, 1]) 242 243.clear() 244 for i in range(12): 245.append(df.iloc[i, 2]) 246 247 性別.clear() 248 for i in range(12): 249 性別.append(df.iloc[i, 3]) 250 251 生年月日.clear() 252 for i in range(12): 253 生年月日.append(df.iloc[i, 4]) 254 clear() 255 index=0 256 hyoji(index) 257 print(no) 258 print() 259 print() 260 print(性別) 261 print(生年月日) 262 263# 各種ボタン設定 264Prev_button = tk.Button(root,text='前ボタン',command = btn_prev).place(width=50,x=330,y=250) 265Next_button = tk.Button(root,text='次ボタン',command = btn_next).place(width=50,x=380,y=250) 266Clear_button = tk.Button(root,text='クリア',command = btn_clear).place(width=50,x=25,y=250) 267Read_button = tk.Button(root,text='読込',command = btn_read).place(width=50,x=130,y=250) 268Save_button = tk.Button(root,text='保存',command = btn_save).place(width=50,x=180,y=250) 269 270 271# テキスト注釈を表示 272lbl_1 = tk.Label(text='No.') 273lbl_1.place(x=30, y=50) 274 275lbl_2 = tk.Label(text='姓') 276lbl_2.place(x=110, y=50) 277 278lbl_3 = tk.Label(text='名') 279lbl_3.place(x=220, y=50) 280 281lbl_4 = tk.Label(text='性別') 282lbl_4.place(x=330, y=50) 283 284lbl_5 = tk.Label(text='生年月日') 285lbl_5.place(x=400, y=50) 286 287# テキストボックス1(No) 288txt_No11 = tk.Entry(width=8) 289txt_No11.place(x=30, y=80) 290 291txt_No12 = tk.Entry(width=8) 292txt_No12.place(x=30, y=110) 293 294txt_No13 = tk.Entry(width=8) 295txt_No13.place(x=30, y=140) 296 297 298# テキストボックス2(姓) 299txt_No21 = tk.Entry(width=12) 300txt_No21.place(x=110, y=80) 301 302txt_No22 = tk.Entry(width=12) 303txt_No22.place(x=110, y=110) 304 305txt_No23 = tk.Entry(width=12) 306txt_No23.place(x=110, y=140) 307 308 309# テキストボックス3(名前) 310txt_No31 = tk.Entry(width=12) 311txt_No31.place(x=220, y=80) 312 313txt_No32 = tk.Entry(width=12) 314txt_No32.place(x=220, y=110) 315 316txt_No33 = tk.Entry(width=12) 317txt_No33.place(x=220, y=140) 318 319 320# テキストボックス4(性別) 321txt_No41 = tk.Entry(width=8) 322txt_No41.place(x=330, y=80) 323 324txt_No42 = tk.Entry(width=8) 325txt_No42.place(x=330, y=110) 326 327txt_No43 = tk.Entry(width=8) 328txt_No43.place(x=330, y=140) 329 330 331# テキストボックス5(生年月日) 332txt_No51 = tk.Entry(width=12) 333txt_No51.place(x=400, y=80) 334 335txt_No52 = tk.Entry(width=12) 336txt_No52.place(x=400, y=110) 337 338txt_No53 = tk.Entry(width=12) 339txt_No53.place(x=400, y=140) 340 341no = ["1","2","3","4","5","6","7","8","9","10","11","12"] 342= ["渡邊","柳川","清野","根本","阿部","稲田","木内","三宅","石村","本郷","山田","清野"] 343= ["沙樹","和臣","菜緒","駿斗","亜依","和徳","喜雄","美南","比呂","香帆","比呂","菜緒",] 344性別 = ["女","男","女","男","女","男","男","女","男","女","男","女","男","女"] 345生年月日 = ["1988/07/15","1966/09/04","1979/06/08","1992/03/14","1977/04/04", 346 "1963/11/06","1972/08/21","1992/11/30","1967/12/07","1965/03/20","1977/04/04","1992/11/30"] 347pageid = 0 348pageid = 0 349hyoji(pageid) 350 351root.mainloop( ) 352 353

投稿2020/09/06 14:42

fuji36_om

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

btn_save()が上手く動かないという話で合ってますか?
csvモジュールを使うのが楽です。

python3

1import csv 2#保存 3def btn_save(): 4 with open('test.csv', mode='w') as file: 5 writer = csv.writer(file) 6 writer.writerow([str(no)]) 7 writer.writerow([str(姓)]) 8 writer.writerow([str(名)]) 9 writer.writerow([str(性別)]) 10 writer.writerow([str(生年月日)])

一行に納める場合はこちら

python3

1import csv 2#保存 3def btn_save(): 4 with open('test.csv', mode='w') as file: 5 writer = csv.writer(file) 6 writer.writerow([str(no),str(姓),str(名),str(性別),str(生年月日)])

投稿2020/09/02 01:32

jeanbiego

総合スコア3966

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuji36_om

2020/09/02 06:24

逆の、読み込みをする場合はどうプログラミングすればよいでしょうか、 今の方法でも、読み書きで悪戦苦闘していますが、 import csv を用いたやり方では皆目見当つきません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問