diff options
-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": "", } |