Important parts of your code¶
Most of the time, one function should be the entry point of your application. In
this instance, I use C as an inspiration for standardizing the use of the
main.main() function. As python file names matter - in contrast to C -
the module holding the main() function is also called main.
![digraph foo {
rankdir = LR
size = "8,5"
overlap = False
pad = 1
"Project" -> "App"
"App" -> "main()" [label = "execute"]
"Project" -> "Tests"
"Tests" -> "test/ folder" [label = "extend"]
"Project" -> "Doc"
"Doc" -> "doc/project/ folder" [label = "extend"]
}](../../_images/graphviz-525f869d02ae5ce38bbc07d608c51083740e7390.png)
Entry points.¶
If you are calling the python interpreter directly on a file, then you’ll need to add a safeguard:
if __name__ == '__main__':
main()
Otherwise, the function is usually given as a gateway, for example if using gunicorn to start a server and deliver a flask application:
$ gunicorn app.main:main
Warning
The entire project is built using Python 3.7+, and in such an example, gunicorn or any other server needs to be carefully setup to use Python 3 as - at the time of this writing - most operating systems and platforms still operate with Python 2.7 as a default.