Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
構成ファイルに辞書を確立し、Python構成パーサーを使用してそれを読み取る方法があるかどうか疑問に思っていましたか?
ありがとう。
構成ファイルを使用evalして単純に実行します。
eval
with open('the_config','r') as config_file: config= eval( config_file.read() )
これは悪であり、セキュリティ ホールであり、他にも多くのことがあるというコメントが表示されます。ただし、Python ソースとまったく同じくらい安全です。
configparserjsonはそれをサポートしていませんが、モジュールを見てみたいと思うかもしれません。
configparser
json
公式ドキュメントからの例の適応:
>>> import json >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4) >>> print(s) { "4": 5, "6": 7 } >>> json.loads(s) {'4': 5, '6': 7}