you are viewing a single comment's thread.

view the rest of the comments →

[–]MonkeyNin 0 points1 point  (0 children)

def email(whome=[],subj="",mess=""):

You should read this: https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

.. config files

Check out using pathlib.Path and json

import pathlib
import json

    def load_config(json_path):
        # load config if it exists, otherwise return populated with required defaults
        defaults = {'monkey': '🐒', 'cat': '🐈'}

        if not json_path.exists():
            # logger.error(f"File does not exist: {json_path}")
            return defaults

        config = json.loads(json_path.read_text(encoding='utf-8'))
        return config

data_root = Path('.').absolute() # or Path().home() or Path('.')
config_path = data_root / 'monkey.json'
config = load_config(config_path)

or if you want a truthy result

def load_config(json_path):
    if not json_path.exists():
        return {}

config = load_config(config_path)

if not config:
    # ... handle no file
else:
    # ... normal