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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.