Python Forum

Full Version: How do you create common functions or classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Having worked through tutorials and a few books, I have not found how this can be done especially in Flask. Being new to Flask and Python, I have a few dumb questions, but hey, that's how some of us learn. Converting from another language may be a challenge working out how to do it in Flask or Python.

I will have some common code that I do not want to have to code again and again and again. I would like to call a function??? for example that can do the common calculations example connect to a database. I will not be using SQLALCHEMY and primarily DB2.

So for example, in a flask script where would I put it or do I put them into a separate file. If I do this, how does it know to call them?

Thank you,
A4ginatl.
It's good to separate your application into separate modules and packages yes. Flask applications are just Python programs really so there's nothing special - you just import the functions from your modules and call them.