diff options
author | nico <nico@magicbroccoli.de> | 2019-06-02 15:30:54 +0200 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2019-06-02 15:30:54 +0200 |
commit | 0d7e2f0c7cef6b7a853107bf37d44816244e7749 (patch) | |
tree | f131604385c6dd5a065d6c5e0ba1ac5c18554cee | |
parent | f0940cc6152faec3695301c1f70430fddc38a898 (diff) |
file system clutter
+ add correct path to config.json to prevent file system clutter
-rw-r--r-- | config.py | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -1,13 +1,18 @@ # -*- coding: utf-8 -*- import json +import os + +# filepath of the config.json in the project directory +path = os.path.dirname(__file__) +filepath = ("/".join([path, "config.json"])) # try to read config.json if nonexistent create config.json an populate it try: - with open("config.json", "r", encoding="utf-8") as f: + with open(filepath, "r", encoding="utf-8") as f: config = json.load(f) except FileNotFoundError: - with open("config.json", "w", encoding="utf-8") as f: + with open(filepath, "w", encoding="utf-8") as f: config = { "name": "", } |