Check the comma as @MosesKoledoye said, the book has:
# 1. The files and directories to be backed up are
# specified in a list.
# Example on Windows:
# source = ['"C:\\My Documents"', 'C:\\Code'] # Example on Mac OS X and Linux:
source = ['/Users/swa/notes']
# Notice we had to use double quotes inside the string # for names with spaces in it.
# 2. The backup must be stored in a
# main backup directory
# Example on Windows:
# target_dir="E:\\Backup"
# Example on Mac OS X and Linux:
target_dir="/Users/swa/backup"
# Remember to change this to which folder you will be using
your code has:
source = [r'C:\\Documents','/home/swaroop/byte', '/home/swaroop/bin']
target_dir =r'C:\\Documents','/mnt/e/backup/'
In the target_dir
assignment the comma makes the right-side of the assignment a tuple. To join two strings together use a +
, not a comma:
target_dir =r'C:\\Documents' + '/mnt/e/backup/'
better yet, use a single string. However, /mnt
is a Linux directory name, not a Windows one. I suspect you actually need:
target_dir="/mnt/e/backup/"
You have also made the Windows path a raw string, which means the two back-slashes will be retained. Either do this:
'C:\\Documents'
or this:
r'C:\Documents'
(unless or course you actually do want \\
)
Edit: I just noticed you also have an indentation problem:
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
should be:
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
Finally, when you say “I copy all the code” and it fails, look to see where yours differs from what it says in the book.
0
solved TypeError: can only concatenate tuple (not “str”) to tuple line 6