the.bay.news

Looking for a better way to import a custom module

Discussions on Python.org
Looking for a better way to import a custom module
Hi All, I’m currently importing a function from a .py file I wrote with the following code. import sys from pathlib import Path resource_dir = str(Path("MyTools.py").resolve().parent.parent) + '\\resources' if resource_dir not in sys.path: sys.path.insert(0, resource_dir) from MyTools import generate_random_password My folder structure is; Workspace —>resources ------->MyTools.py ------->.env —>project1 ------->project1_main.py —>project2 ------->project2_main.py This works but gi...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.