Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable Scope for Scripts
#7
(Dec-01-2017, 07:40 PM)QueenSvetlana Wrote: , is using global variables the way I have a concern?
No really,i like to do if __name__ == '__main__': as a natural way to see that script end.
Also make it easier to test,if import code it don't automatically run.
So here is not much exposed before doing the final call.
def read_data_from_file(file_to_read):
    #code to read from file and build list
    return list_of_files

def copy_files_to_backup_folder(file_to_copy):
    #code to copy files
    pass

def is_backup_successful():
    #code to verify that the a compressed file was created
    pass

def write_log_file(file_name):
    #code to generate a log file
    pass

def backup(file_name):
    files_to_backup = read_data_from_file(file_name)
    for f in files_to_backup:
        copy_files_to_backup_folder(f)
    is_backup_successful()
    write_log_file(file_name)

if __name__ == '__main__':
    # Here do last step that start it
    file_name = "some/path/to/file"
    backup(file_name)
Reply


Messages In This Thread
Variable Scope for Scripts - by QueenSvetlana - Dec-01-2017, 03:34 AM
RE: Variable Scope for Scripts - by snippsat - Dec-01-2017, 02:40 PM
RE: Variable Scope for Scripts - by QueenSvetlana - Dec-01-2017, 02:59 PM
RE: Variable Scope for Scripts - by snippsat - Dec-01-2017, 06:01 PM
RE: Variable Scope for Scripts - by QueenSvetlana - Dec-01-2017, 07:40 PM
RE: Variable Scope for Scripts - by RickyWilson - Dec-01-2017, 06:26 PM
RE: Variable Scope for Scripts - by snippsat - Dec-01-2017, 08:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,966 Nov-07-2023, 09:49 AM
Last Post: buran
  Library scope mike_zah 2 889 Feb-23-2023, 12:20 AM
Last Post: mike_zah
  Scope of variable confusion Mark17 10 2,981 Feb-24-2022, 06:03 PM
Last Post: deanhystad
  Variable scope issue melvin13 2 1,619 Nov-29-2021, 08:26 PM
Last Post: melvin13
  Variable scope - "global x" didn't work... ptrivino 5 3,126 Dec-28-2020, 04:52 PM
Last Post: ptrivino
  Python Closures and Scope muzikman 2 1,894 Dec-14-2020, 11:21 PM
Last Post: muzikman
  Block of code, scope of variables and surprising exception arbiel 8 3,508 Apr-06-2020, 07:57 PM
Last Post: arbiel
  Help with Global/Coerced Variable (Understanding Scope) Rev2k 6 3,599 Jan-09-2020, 03:43 AM
Last Post: Rev2k
  Solving a scope issue profconn1 4 2,676 Nov-01-2019, 07:46 PM
Last Post: profconn1
  Namespace and scope difference Uchikago 9 4,702 Jul-03-2019, 03:36 PM
Last Post: Uchikago

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020