Snake_Byte[10] – Module Packages

Complexity control is the central problem of writing software in the real world.

Eric S. Raymond
AI-Generated Software Architecture Diagram

Hello dear readers! first i hope everyone is safe. Secondly, it is the mondy-iest WEDNESDAY ever! Ergo its time for a Snake_Byte!

Grabbing a tome off the bookshelf we randomly open and it and the subject matter today is Module Packages. So there will not be much if any code but more discussion as it were on the explanations thereof.

Module imports are the mainstay of the snake language.

A Python module is a file that has a .py extension, and a Python package is any folder that has modules inside it (or if your still in Python 2, a folder that contains an __init__.py file).

What happens when you have code in one module that needs to access code in another module or package? You import it!

In python a directory is said to be a package thus imports are known as package imports. What happens in import is that the code is turned into a directory from a local (your come-pooter) or that cloud thing everyone talks about these days.

It turns out that hierarchy simplifies the search path complexities with organizing files and trends toward simplifying search path settings.

Absolute imports are preferred because they are direct. It is easy to tell exactly where the imported resource is located and what it is just by looking at the statement. Additionally, absolute imports remain valid even if the current location of the import statement changes. In addition, PEP 8 explicitly recommends absolute imports. However, sometimes they get so complicated you want to use relative imports.

So how do imports work?

import dir1.dir2.mod
from dir1.dir2.mod import x

Note the “dotted path” in these statements is assumed to correspond to the path through the directory on the machine you are developing on. In this case it leads to mod.py So in this case directory dir1 which is subdirectory dir2 and contains the module mod.py. Historically the dot path syntax was created for platform neutrality and from a technical standpoint paths in import statements become object paths.

In general the leftmost module in the search path unless it is a home directory top level file is exactly where the file presides.

In Python 3.x packages changed slightly and only applies to imports within files located in package directories. The changes include:

  • Modifies the module import search path semantic to skip the package’s own directory by default. These checks are essentially absolute imports
  • Extension of the syntax f from statements to allow them to explicitly request that imports search the packages directories only, This is the relative import mentioned above.

so for instance:

from.import spam #relative to this package

Instructs Python to import a module named spam located in the same package directory as the file in which this statement appears.

Similarly:

from.spam import name

states from a module named spam located in the same package as the file that contains this statement import the variable name.

Something to remember is that an import without a leading dot always causes Python to skip the relative components of the module import search path and looks instead in absolute directories that sys.path contains. You can only force the dot nomenclature with relative imports with the from statement.

Packages are standard now in Python 3.x. It is now very common to see very large third-party extensions deployed as part of a set of package directories rather than flat list modules. Also, caveat emptor using the relative import function can save memory. Read the documentation. Many times importing AllTheThings results in major memory usage an issue when you are going to production with highly optimized python.

There is much more to this import stuff. Transitive Module Reloads, Managing other programs with Modules (meta-programming), Data Hiding etc. i urge you to go into the LazyWebTM and poke around.

in addition a very timely post:

PyPl is running a survey on packages:

Take the survey here -> PyPl Survey on Packages

Here some great comments and suggestions via Y-Combinator News:

Y-Combinator News Commentary on PyPl Packages,

That is all for now. i think next time we are going to delve into some more scientific or mathematical snake language bytes.

Until Then,

#iwishyouwater <- Wedge top 50 wipeouts. Smoookifications!

@tctjr

MUZAK TO BLOG BY: NIN – “The Downward Spiral (Deluxe Edition)”. A truly phenomenal piece of work. NIN second album, trent reznor told jimmy iovine upon delivering the concept album “Im’ Sorry I had to…”. In 1992, Reznor moved to 10050 Cielo Drive in Benedict Canyon, Los Angeles, where actress Sharon Tate formally lived and where he made the record. i believe it changed the entire concept of music and created a new genre. From an engineering point of view,  Digidesign‘s TurboSynth and  Pro Tools were used extensively.

It Is An Honor To Say “GoodBye”.

No one ever told me that grief felt so like fear.

C.S. Lewis
An AI-Generated Image

First, i hope everyone is safe, especially on this day when belief systems ran completely amok. Second, this day also holds a place for me that i will not go into but if you are a good internet sleuth you can figure it out.

Today i did something i have never done nor did i think i could do because of several factors. However into the breach once more and low and behold i pulled it off. The man with me is an expert at this activity and gave me some pointers as to how to perform the said activity. As i was saying goodbye to the man who is one of the closest people in my life we volitionally hugged each other and shook hands a certain way.

On this day i reflected on an Uber ride that i had years ago where a man picked me up. We started talking as it was a pretty good drive from SFO to the Marines’ Memorial Club & Hotel where i was speaking.

There are places I’ll remember
All my life though some have changed
Some forever, not for better
Some have gone and some remain

All these places have their moments
With lovers and friends I still can recall
Some are dead and some are living
In my life I’ve loved them all

The driver as it turns out was a former senior salesperson at salesforce. As i always say you never know what someone has been through so don’t judge them by how they make a living. We discussed most of the “-isms” and then he said, “Mr Ted i found comfort in the christian bible. Have you read it?” i said i have read it three times and i prefer the old testament. i asked him why? he said it helped him through the hard times of his life. He was talking about his family in past tense and i was very sensitive to prying to much into his business. i asked him what type of hardships. He said his family lived during the years of Pol Pot and the Cambodian genocide and his family were all murdered. i really didnt know what to say except “My Condolences”. He said, “Thank you Mr Ted. i have found peace and remember it is an honor to say goodbye to someone and to always make it count as you never know when you will see them again. As a matter of fact i do not tell people Goodbye i say i love you or be safe.”

We arrived at the Marine Hotel. We got out of the car and he said , “Mr Ted it has been an honor speaking with you i hope you enjoy your life. Be Safe Mr Ted.”

That left an indelible imprint on my mind.

Though I know I’ll never lose affection
For people and things that went before
I know I’ll often stop and think about them
In my life I love you more

On 9.11 – Today many lost loved ones. Grief, as Mr Lewis states, is very much like fear except you cannot Un-Grieve. You can be unafraid. Grief, as it turns out, is never-ending. There is no invertible transformation that makes you not grieve.

We have been so programmed to buck it up – suck it up, buttercup that everything tries to gloss over the loss. Whether a human or a family pet, it is ok to grieve. There are people and animals in my life that i will never recover from losing and for the longest time i beat myself up for not bucking up buttercup.

Further contemplating this i believe Grief is fractal. Zoom in on a fractal it evolves and changes yet holds the same shape ad infinitum1.

Mandelbrot Set Generated Fractal

Grief as it turns out appears at least to me to be closely aligned. The more you peel it back the more complex it gets.

Same Fractal Zoomed

Does time heal Grief? Not really. It is the memory that fades. Ergo other memories fade as a function of our leaky memory system.

We deal with healing in different ways. The Uber driver found solace in a religious text, others workout, some self-medicate, others try to replace the human or animal.

We want it to go away.

i say we should acknowledge the pain of grief and realize it and let it happen then further acknowledge that the next person or animal who is essential to you, use the opportunity and find strength in telling them “Be Safe, See ya Real Soon, or i love you more.” However above all, if you cherish that friend or loved one, it is an honor to tell them upon them walking out the door. Let them know it.

Until Then,

#iwishyouwater. <- Laird Hamilton on a Paddle board

@tctjr

Muzak To Blog By: A band called Papir.

[1] The Mandelbrot set is the set of complex numbers c for which the function $$f_{c}=z^2+c$$ does not diverge to infinity when iterated from $$z=0$$