Just need some clarification on how to design a python script file test.py.
-
When defining functions, do they have to go on the top of the file right after the imports?
-
should I be doing that main check in my file?
-
I want to run this file on my server as a cron job. If the file gets too big (I have my sqlalchemy definitions in it also), how can I break the file into multiple files? I want this easy to deploy by just dropping the files into a folder in my server.
Most scripts look something like the following:
So the body of your script is mainly composed of function/class definitions. There (usually) is very little code that isn’t inside a function/class definition.
I would try to group the functions in whatever way facilitates organization and readability. If you believe a function can be reused in places other than that particular script, then place it in a module, and import that module into this script.
Define
PYTHONPATHandPATHin your crontab. Then you should have no problem running your script from cron.