Ok so I get all that, and changed my script, and yes it works. but I don't like it. BUT is works.
Like, just moving "MOST_RECENT_BACKUP = SET_MOST_RECENT_BACKUP()" and "OLDEST_BACKUP = SET_OLDEST_BACKUP()"
out of the main() but after INITIAL_SETUP() function breaks it.
I guess it is a classic case of trying to run before you can walk.
Thanks again for your help.
After reviewing it some more, I understand why is breaks when the variable are breaking outside the main() function, because the intial_setup() function only get called then. Therefore not set before then.
#!/usr/bin/python3* ''' Module name: Author: Contact: Desc: ''' __version__ = '0.0.1' import shutil import os, os.path import datetime TODAYS_DATE = str(datetime.date.today()) NUMBER_OF_BACKUP = 3 BACKUP_LOCATION = '/home/Superusr/Backup_Scripts/Test_01/Save_Location/' FOLDER2BACKUP = '/home/Superusr/Backup_Scripts/Test_01/Sample_Folder' CURRENT_BACKUP_NAME = FOLDER2BACKUP + "_" + TODAYS_DATE CURRENT_LIST_OF_BACKUPS = [] def GET_MOST_RECENT_BACKUP_NAME(): print("Step 2...") for names in os.listdir(BACKUP_LOCATION): CURRENT_LIST_OF_BACKUPS.append(names) CURRENT_LIST_OF_BACKUPS.sort() def SET_MOST_RECENT_BACKUP(): print("Step 3...") RESULT = CURRENT_LIST_OF_BACKUPS[-1] return RESULT def SET_OLDEST_BACKUP(): print("Step 4...") RESULT = CURRENT_LIST_OF_BACKUPS[0] return RESULT def INITIAL_SETUP(): print("Step 1...") GET_MOST_RECENT_BACKUP_NAME() def main(): INITIAL_SETUP() MOST_RECENT_BACKUP = SET_MOST_RECENT_BACKUP() OLDEST_BACKUP = SET_OLDEST_BACKUP() print("Most recent backup is: {}".format(MOST_RECENT_BACKUP)) if __name__ == "__main__": main()I don't like it because it doesn't future proof the code, I know what I want to do next and I will have to switch it up.
Like, just moving "MOST_RECENT_BACKUP = SET_MOST_RECENT_BACKUP()" and "OLDEST_BACKUP = SET_OLDEST_BACKUP()"
out of the main() but after INITIAL_SETUP() function breaks it.
I guess it is a classic case of trying to run before you can walk.
Thanks again for your help.
After reviewing it some more, I understand why is breaks when the variable are breaking outside the main() function, because the intial_setup() function only get called then. Therefore not set before then.