環境
macOS Sierra
Python3.6.0
わからないこと
初歩的な質問になってしまいますが、「データベースを使うこと」の意味はなんでしょうか?
例えば、userとpasswordを登録し、参照し使えるようなプログラムを書く時、dictionary機能で十分だと思うのです。
以下、簡単なログイン機能をpickleでつくってみました。
# accounts.pickleファイル内に{"user1":"pass1","user2":"pass2"}があるとします。 import pickle def open_file(): with open('accounts.pickle', mode='rb') as f: accounts = pickle.load(f) return accounts def save_file(accounts): with open('accounts.pickle', mode='wb') as f: pickle.dump(accounts,f) def add_account(accounts): while True: new_username = input('Enter a new username:') if new_username not in accounts: new_password = input('Enter a new password:') accounts[new_username] = new_password save_file(accounts) print('NOW YOU HAVE A NEW ACCOUNT.') break else: print('ALREADY EXIST!') continue def login(accounts): username = input('Enter your account name:') if username in accounts.keys(): password = input('Enter your password:') if password == accounts[username]: print('LOGIN SCCEEDED!') else: print('WRONG PASSWORD!') else: print("NO EXIST") accounts = open_file() add_account(accounts) login(accounts)
結局のところ、情報の単純なファイル管理と、データベースでの管理の違いはなんでしょうか?
userに対する情報量が多くなってくるとめんどくさいのでデータベースを・・・という考えなのでしょうか。
それとも、セキュリティ面からの必要性でしょうか(だとすればどう違うのでしょうか)
以上、データ保存についてよくわらない小生にご教授くださいm(_ _)m
追記:
誤解を招く例文で申し訳有りません。自分は必ずしも「ログイン機能」を作りたいわけではありません。
「果物の名前と値段」、「映画の作品名と監督名」などの管理を「データベースで行う」のか「平ファイルで行う」のか、そこらへんの判断基準はどうであろうかというのがこの質問の意図です。
わかりにくくてすみません・・・。
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/03 12:23
退会済みユーザー
2017/03/03 12:35