There are at least two questions being asked here (arguably a lot more, so I'll have to ignore many of the little ones), but the solution to both comes down to writing a class that effectively encapsulates retrieving (your) data from (your) files. Since you specifically asked whether it should be a class or something else, in this language classes are the main data abstraction that's capable of remembering things, which is obviously necessary if you want to avoid reading the same file over and over, so that's why this should be a class.
Since you haven't told me what any of the functions in module 2 actually do after calling func1, I'm going to make up some fairly generic requirements. Let's pretend func1 reads a comma-separated value file of numbers. Say func2 gets the sum of all numbers. Say func3 gets the average and standard distribution of each row.
What you want to do is write a class that handles reading and parsing these files, and exposes methods to retrieve certain aspects of the data it finds. For instance, you might have the class' constructor take a single filename/filepath argument, so the file gets read exactly once during construction, and all method calls on the object merely manipulate the in-memory representation of the data you've already read. The important thing is that no other module should know (exactly) how this class gets its data. They should see getNums() and getStdDev() and getTotal() methods, but they probably shouldn't know whether these values come from a .csv file or an Excel spreadsheet or a website or wherever, and they certainly should not know whether that file/site is being cached or not.
If you do this right, it will be trivial to add getEigenvectors() and whatnot to module2 whenever you feel like it without even thinking about what module1 is doing. That is always the main goal of reducing coupling. This applies to pretty much every language that supports OOP.
If you need more specific help you'll have to explain more about what these functions actually do and why the generic advice I just gave is insufficient.
I cannot comment so instead I'll answer or lead you there with rhetorical questions:
First, how are you intending on launching as well as using this program? You are building a python package by using __init__.py's but you are executing a module (bin/app.py) within the package as __main__. This is not a typical setup.
Do you plan on importing this package of yours into some other python script? Maybe you don't need a package at all and can use a few scripts. Generally all python files related to some function would be in one cohesive package (perhaps you don't need that top-level __init__.py).
Did you mean for bin/app.py to be executable since it appears that's your only use of it? Add a #!/usr/bin/env python
run command to the top of the file, and IMO make the file called app
and executable $ chmod +x bin/app
.
It would be good to google how python finds modules, how to construct a package, and how env's PYTHONPATH and sys.path work. If your module name doesn't make it to sys.path or is relative to your current directory python won't find it. I added some links below.
If you don't intend on using a python package mechanics you could simply (answer) perform a sys.path.append(os.path.join(os.getcwd(), 'Fragment_Maker'))
or sys.path.append(os.path.join(os.dirname(__file__), '..', 'Fragment_Maker'))
before your import maker
, depending on how you intend on launching your application. Otherwise your question cannot be answered without assumptions from above (e.g. maybe you'll want to put your python script app at top level, keep Fragment_Maker a package, perform a from Fragment_Maker import maker
), but assuredly you can now figure it out with these resources:
Best Answer
When You import
Y
module, that imports functions from moduleX
withfrom X import *
, all functions fromX
are available as they were inY
( You can thing of that, like pasting content ofX
intoY
).And, when you have multiple defs, Python will take the last one. So to override functions You have just to redefine those function after you import
X
.Also, when You want to use original function from
X
in YourY
, you can add aditionalimport X
and access it withX.functionName()
.Example:
module1.py
module2.py
run.py
Example's result: