Data log files

I need to detect my OS before I start my logfiles program.

The following code from Section 6 is saved as Exercises_10/os_utilities.py

""""
OS utilities, forked from the Comm module of SD-Node, written c. 2017
Tested with Python >=3.6
By: JOR
    v0.1    26AUG21     
"""
import platform

def detect_os()->str:
    # Detect the OS in use
    return platform.system()

if (__name__ == '__main__'):
    print(f"This module is called {__name__} and executes as a standalone script")
    
    # Check the OS in use, lower case
    my_os = detect_os()
    my_os = my_os.lower()
    
    # Parse the response
    if my_os == "windows":
        print("Your system is Windows")
    elif my_os == "linux":
        print("Your system is Linux")
    elif my_os == "darwin":
        print("Your Apple system is MacOS")
    elif my_os == "cygwin":
        print("Your Apple system is MacOS")
    elif my_os == "aix":
        print("Your IBM system is AIX")
    else:
        print(f"Unidentified system = {my_os}")
else:
    pass
    #print(f"This module is called {__name__} and is being called by another script")

Note that at the end, I have commented out my diagnostic text and added a pass statement. Interestingly, I can copy and paste from the if (__name__ == '__main__'): section if I want to use functions in another program.

When I’m saving logfiles, I like to have unique filenames. I wrote the following file long ago in my utilities package and I am copying it now as Exercises/file_utilities.py

The path that I use to store my log files is dependent on the operating system I'm using. As you can guess from the Linux path, this is intended for a Raspberry Pi.

Once again, I can copy and paste from the if (__name__ == '__main__'): section if I want to use these functions in another program.