Created
May 21, 2018 04:49
-
-
Save pythonsuezo/72ecf38938d9a2dbdd82092cff715b31 to your computer and use it in GitHub Desktop.
クリップ画像保存器その4 INIファイルを使うコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os,sys, configparser | |
| path = os.path.dirname( sys.argv[0] ) | |
| # 設定ファイルの場所を決める | |
| INI = path + "/ini.conf" | |
| conf = configparser.SafeConfigParser() | |
| conf.read(INI) | |
| if os.path.exists(INI): | |
| print("読み込み成功") | |
| if conf.has_option("option", "comment"): # セクション[option]の中にcommentパラメータが存在するか? | |
| comment = conf.get("option", "comment") # comf.get(セクション,パラメータ)で読出し | |
| print("comment:", comment) | |
| else: | |
| print("設定ファイルがありません") | |
| conf.add_section("option") # 存在しない場合はつくる | |
| conf.set("option","comment","hello world") # conf.set(セクション、パラメータ、値) | |
| print("INIに書き込み") | |
| f = open(INI,"w") | |
| conf.write(f) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment