Python Forum
How do you create common functions or classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you create common functions or classes
#1
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.
Reply
#2
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020