INNER CODE UNIT · Python

dict_to_json_file

AbdBarho/stable-diffusion-webui-docker · services/AUTOMATIC1111/config.py:29

def dict_to_json_file(target_file: str, data: dict):
  """Write dictionary to specified json file"""

  with open(target_file, 'w') as f:
    json.dump(data, f)

def json_file_to_dict(config_file: str) -> dict|None:
   """Load json file into a dictionary. Return None if file does not exist."""

   if os.path.isfile(config_file):
    with open(config_file, 'r') as f:
      return json.load(f)
   else:
      return None

def replace_if_invalid(value: str, replacement: str, pattern: str|re.Pattern[str]) -> str:
  """Returns original value if valid, fallback value if invalid"""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…