best_practices_2.py

#!/usr/bin/python3
# ==================================================================
# From: https://www.youtube.com/watch?v=lOeIDvyRUQs
#
# Summary of Best Proctices
# 1. Put code that takes a long time to run or has other effects
#    on the computer in a function or class, so you can control
#    exactly when that code is executed
# 2. Use the different values of __name__ to determine the context
#    and change the behavior of your code with conditional
#    statements
# 3. Name the entry point function main() in order to communicate
#    the intention of the function, even though Python does not
#    assign any significance to a function names main()
# 4. If you want to reuse functionallity from your code, define
#    the logic in functions outside main() and call thoes function
#    within main()
# ==================================================================

from time import sleep

print("This is my file to demonstrate best practices.")

def process_data(data):
    print("Begining data processing...")
    modified_data = data + " that has been modified"
    sleep(3)
    print("Data processing finshed")
    return modified_data

def read_data_from_web():
    print("Reading data from the web")
    data = "data from the web"
    return data

def write_data_to_database(data):
    print("Writing data to a database")
    print(data)

def main():
    data = read_data_from_web()
    modified_data = process_data(data)
    write_data_to_database(modified_data)

if __name__ == "__main__":
    main()