Код: Выделить всё
base---
|--- dir1
| |---test2.py
|--- public.py
|--- config.json
|--- test1.py
Код: Выделить всё
def getCfg(key):
with open("config.json", 'r',encoding='utf-8') as f:
cfg=json.load(f)
return cfg[key]
Код: Выделить всё
import public
public.getCfg("my_key")
Код: Выделить всё
current = os.path.dirname(os.path.realpath(__file__))
parent = os.path.dirname(current)
sys.path.append(parent)
import public
public.getCfg("my_key")
Код: Выделить всё
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
Моя версия Python — 3.9. Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/789 ... -by-myself