Dr. Varshita Sher
1 min readOct 11, 2021

--

Hi there. You are quite correct - scripts is not defined as a package and therefore you cannot do this:

> from scripts import yolo

However, scripts is like any other directory and we are providing the absolute path to the module we want (i.e. example1.py) and thus are able to import yolo from it:

> from scripts.example1 import yolo

In fact, you could have accessed the modules within utils without converting it into a package (i.e no need for a __init__.py file). All you had to do was import the modules in it individually:

> from utils.lower import to_lower

> from utils.upper import to_upper

> from utils.lower import to_lower

For me, this syntax is definitely not succinct and therefore it made sense for me to turn this into a package. Having said that, there is no particular structure that one must necessarily follow. It all depends on how packages or functions will be imported into your other files.

--

--

Dr. Varshita Sher
Dr. Varshita Sher

Written by Dr. Varshita Sher

FTSE 100 Tech Leader 🚀 | Data Science & Generative AI | Oxford Alumni | 2x Top writer on Medium | Editor of Trusted Data Science @ Haleon | Synapgen.ai

No responses yet