Zip_command = "rar a% s% s"% (target,' '.join (source) in the python backup script

the whole script can be run, but there is something I don"t understand

Zip_command = "rar a% s% s"% (target," ".join (source) is not understood in the

script. I hope someone who understands it can explain the principle.

-sharp!/usr/bin/python
-sharp Filename:backupup_ver5.py

import os
import time

source = ["D:\\python-source\\nihao.txt"]

target_dir = "D:\\python-backup\\"

today = target_dir + time.strftime("%Y%m%d")

now = time.strftime("%H%M%S")

comment = input("Enter a comment -->") 
if len(comment) == 0:
    target = today + os.sep + now + ".zip"
else:
    target = today + os.sep + now + "_" +\
    comment.replace(" ","_") + ".zip"
    
if not os.path.exists(today):
    os.mkdir(today)
    print("Successfully create directory",today)
    
zip_command = "rar a %s %s"%(target," ".join(source))

if os.system(zip_command) == 0:
    print("Successful backup to",target)
else:
    print("Backup FAILE")
Mar.25,2022

'. Join (source) just concatenate the contents of source into strings through spaces, for example:

>>> print ' '.join(s)
s aa
After

is spliced, pass in "rar a% s% s" with target and replace it with the actual command, and then execute it with os.system .

Menu