Python was supposed to be easy and straightforward

 Don't worry your pretty print head about it, they say. Just invoke this magic incantation and everything will be fine.

Of course, it's never that simple. Today's travail involves creating your own custom code modules and trying to import them into your main flow code.

Turns out the Python interpreter does a background scan and fill-in of some sort of namespace dictionaries. And if it doesn't detect your custom module or package, your import statement won't work.

I still don't fully understand it all. A good place to start is with this CS professor's explanation: Explaining the different import methods in Python.

As you move along in this back alley of the Python language, you learn it's a good idea to have a Dunder file (not a Dunder "method") named __init__.py incorporated in you custom module or package. One explanation can be found in NeuroNine's YT post here: Importing Your Own Python Modules Properly

The overall trick for learning is to ask ChatGPT or another AI with a proper prompt like, "How to import your own custom modules into the main code file in Python?". Or put the same prompt in the search bar of YouTube

More to Explore
The mysterious __init__.py file (how to use it)
tbd .....

Comments

Popular posts from this blog

Git-ten Up to Speed

True Confessions

Obsidian is Not King of the Hill