pathlib support
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from pathlib import Path
|
||||
from traceback import print_exc
|
||||
from typing import Any, Union
|
||||
|
||||
@@ -11,11 +12,11 @@ def logWrite(message: str, debug: bool = False) -> None:
|
||||
print(f"{message}", flush=True)
|
||||
|
||||
|
||||
def jsonLoad(filepath: str) -> Any:
|
||||
def jsonLoad(filepath: Union[str, Path]) -> Any:
|
||||
"""Load json file
|
||||
|
||||
### Args:
|
||||
* filepath (`str`): Path to input file
|
||||
* filepath (`Union[str, Path]`): Path to input file
|
||||
|
||||
### Returns:
|
||||
* `Any`: Some json deserializable
|
||||
@@ -37,12 +38,12 @@ def jsonLoad(filepath: str) -> Any:
|
||||
return output
|
||||
|
||||
|
||||
def jsonSave(contents: Union[list, dict], filepath: str) -> None:
|
||||
def jsonSave(contents: Union[list, dict], filepath: Union[str, Path]) -> None:
|
||||
"""Save contents into json file
|
||||
|
||||
### Args:
|
||||
* contents (`Union[list, dict]`): Some json serializable
|
||||
* filepath (`str`): Path to output file
|
||||
* filepath (`Union[str, Path]`): Path to output file
|
||||
"""
|
||||
try:
|
||||
with open(filepath, "w", encoding="utf8") as file:
|
||||
@@ -63,7 +64,7 @@ def configGet(key: str, *args: str) -> Any:
|
||||
### Returns:
|
||||
* `Any`: Value of provided key
|
||||
"""
|
||||
this_dict = jsonLoad("config.json")
|
||||
this_dict = jsonLoad(Path("config.json"))
|
||||
this_key = this_dict
|
||||
for dict_key in args:
|
||||
this_key = this_key[dict_key]
|
||||
|
Reference in New Issue
Block a user