Is there any suggestions or standards of module dependency design of Python?
Question: Suppose all that need to be considered are only user defined functions and
system modules.

I've created 2 modules based on it's logical structure, then I'm not sure
what's next.

Say I put 10 functions in `fm1.py` and 8 functions in `fm2.py`. Functions in
both `fm1.py` and `fm2.py` would need some system modules `m1` and `m2`, as
long as some other user defined functions `f1()`, `f2()`.

What I do now is create another file `i1.py`, it imports system modules `m1`
and `m2` and the definition of `f1()` and `f2()` are also included in this
file. Then both `fm1.py` and `fm2.py` import `i1.py1` and finally a `main.py`
imports `fm1.py` and `fm2.py`.

I ran `main.py` and no error occurred, however, I wonder the way I designed
the dependency may not be the suggested way.

So, is there any suggestions or standards of module dependency design?


Answer: The correct way to do this would be to **pass** the functions `f1()` and
`f2()` to whatever function needs them in `fm1.py` and `fm2.py`. For example,
if you originally had something like

    
    
    def length(a,b):
        return metric(a,b)
    

where you defined `metric()` in `i1.py`. You could instead do it like

    
    
    def length(a,b,metric):
        return metric(a,b)
    

Then, if someone wanted to use the function they could import your module and
call it like this:

    
    
    from foo import length
    
    def metric(a,b):
        return a[0]*b[0] - sum(x*y for x, y in zip(a[1:],b[1:]))
    
    norm = length(a,b,metric)
    

