I have a python script with a structure that looks like the following:
/
__init__.py
main.py
/modules
fbm.py
I am attempting to split some functions out from main.py into fbm.py and then import fbm.py as a module using.
sys.path.extend([f'{item[0]}' for item in os.walk("./app/modules/") if os.path.isdir(item[0])])
import fbm
This is working.
What I am having trouble with is where I need to call pandas (or another import) from a module.
I'm currently importing pandas in main.py with import pandas as pd
.
When I call the function from fbm
an error is thrown as soon as it hits a reference to pd
stating that NameError: name 'pd' is not defined
. pd
is defined in main.py, but not fbm.py. It thus works in main, but not in fbm.
So, my question is: Is it good and appropriate to import pandas as pd
in both the main.py and each module which requires pandas?
- Will this have an impact on memory usage, ie loading multiple copies of pandas
- is there a better way to handle this?