From 0d7e2f0c7cef6b7a853107bf37d44816244e7749 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 2 Jun 2019 15:30:54 +0200 Subject: file system clutter + add correct path to config.json to prevent file system clutter --- config.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index ff6f9fa..fac5f9b 100644 --- a/config.py +++ b/config.py @@ -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": "", } -- cgit v1.2.3-54-g00ecf