Hi,
my question is simple and I am not sure it is the right place to ask it…
I have a file with functions that I would like to use in a steamlit app ie:
the structure of my program is as follow:
First question:
How is it possible to have this func.py program in the app ? How to “load” it in testing mode ie while I use streamlit run “/Users/jacques/Library/Mobile Documents/com~apple~CloudDocs/Projets/Quantalys/Home.py” ?
Second question:
in the deployment phase, how to have this in GitHub later and use it ? what should be the directory to use
One question, is the func.py a utility function that you’re then importing into one of the pages or Home.py?
If yes, you will have to create a folder within the root directory and move the func.py file into it. Also don’t forget to add an empty __init__.py file in the same folder. This makes that folder (say utils) a Python package.
The __init__.py file should be empty. Its purpose is to signal to Python that the directory it’s in should be treated as a Python package which subsequently allows you to import from modules (functions) in that directory.
For importing example, in your Home.py , 1_Page_one.py , and any other file where you need to use functions from func.py, you would use:
import utils.func to import the whole module, or
from utils.func import specific_function to import a specific function within your func.py.
So when you import a module in Python, in this case import utils.func, you need to use the module name as a prefix when calling functions from that module. In your case, since test is a function inside func.py which is in the utils folder, you should call it using utils.func.test(a,b). If this is not working, double-check that you don’t have any typos in the functions or import statement.
It should look like so somewhere in your code:
import utils.func
result = utils.func.test(a, b)
Please feel free to share a link to your repository with the full code so I can troubleshoot it better for you.