I want to make different language files for my script, and the way I intended to set this up (after some googling) is that based on user's choice, a .py
file (%cwd%\locale\en.py
, %cwd%\locale\ru.py
etc) with all strings saved as variables is imported using importlib.import_module
, and all text after that is formatted with f-strings using variables from the imported file.
I've tried providing strings with the relative name such as locale.en
(as I would in a normal import) and the full path acquired using str(Path(Path.cwd() / 'locale' / 'en.py'))
(print
showed that the directory is acquired correctly), and in both cases I get a ModuleNotFoundError
.
I kinda sorta understand why I would get it using the relative name, but how come the full path is not enough? I keep finding answers mentioning that __init__.py
is required in the locale
folder, but I also find answers that make no mention of it.
Not sure if it's relevant, but in the full path's ModuleNotFoundError
every backslash is doubled (e.g. C:\\Script\\locale\\en
)