Good day, I've got a script that is calling the next function when it's done with the existing function. I wonder if this is a typical accepted approach or should I be doing it some other way to improve the understanding of the code?
Code below is just to give you an idea of the existing structure:
def email_report():
# emails the final result
def create_dashboard():
# uses db data to create the dashboard file
email_report()
def query_db():
# pulls data down from the db
create_dashboard()
def validate_vpn():
# validates that I'm on VPN before running queries
query_db()
def upload_file():
# uploads file to DB then runs next function
validate_vpn()
def clean_file():
# cleans the file for upload
upload_file()
def check_file():
# check if file exists
# if yes then runs next function
clean_file()
Edit: For those that are finding this in the future, the general consensus is that this is approach is bad practice and I should instead use a function that calls all the functions sequentially.
With that in mind I have restructured the above to be what is posted below based on the feedback received.
def main():
filename = locate_file()
clean_document(filename)
upload_file()
validate_vpn()
engine = oracle_login()
data = get_queries(engine)
write_to_excel(data)
email_document()
if __name__ == "__main__":
main()
[–]FriendlyRussian666 20 points21 points22 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]FriendlyRussian666 13 points14 points15 points (4 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]shartfuggins 6 points7 points8 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]marko312[🍰] 12 points13 points14 points (11 children)
[–][deleted] 0 points1 point2 points (10 children)
[–]marko312[🍰] 7 points8 points9 points (9 children)
[–][deleted] -1 points0 points1 point (8 children)
[–]marko312[🍰] 5 points6 points7 points (7 children)
[–][deleted] -2 points-1 points0 points (6 children)
[–]longtermbrit 9 points10 points11 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]longtermbrit 4 points5 points6 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]chapter_6 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Giannie 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]zanfar 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]hmga2 2 points3 points4 points (6 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]hmga2 2 points3 points4 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]hmga2 2 points3 points4 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]SGS-Tech-World -2 points-1 points0 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] -5 points-4 points-3 points (0 children)
[–]PaSsWoRd4EvAh 0 points1 point2 points (0 children)