TypeError: can only concatenate tuple (not "str") to tuple line 6
<pre><code>import os

import time

source = [r'C:\\Documents','/home/swaroop/byte', '/home/swaroop/bin']

target_dir =r'C:\\Documents','/mnt/e/backup/' 

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

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

os.path.exists(today)

os.mkdir(today)

print 'Successful created directory', today

target = today + os.sep + now + '.zip'

zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))

if os.system(zip_command) == 0:

print 'Successful backup to', target

else:
    print 'Backup FAILED'

today = target_dir + time.strftime("%Y%m%d")
</code></pre>

<p>Plees help</p>

<p>TypeError: can only concatenate tuple (not "str") to tuple</p>

<p>Check the comma as @MosesKoledoye said, the <a href="http://files.swaroopch.com/python/byte_of_python.pdf" rel="nofollow">book</a> has:</p>

<pre><code># 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
</code></pre>

<p>your code has:</p>

<pre><code>source = [r'C:\\Documents','/home/swaroop/byte', '/home/swaroop/bin']

target_dir =r'C:\\Documents','/mnt/e/backup/' 
</code></pre>

<p>In the <code>target_dir</code> assignment the comma makes the right-side of the assignment a <em>tuple</em>.  To join two strings together use a <code>+</code>, not a comma:</p>

<pre><code> target_dir =r'C:\\Documents' + '/mnt/e/backup/' 
</code></pre>

<p>better yet, use a single string.  <strong>However</strong>, <code>/mnt</code> is a Linux directory name, not a Windows one.  I suspect you actually need:</p>

<pre><code> target_dir = '/mnt/e/backup/' 
</code></pre>

<p>You have also made the Windows path a raw string, which means the two back-slashes will be retained.  Either do this:</p>

<pre><code>'C:\\Documents'
</code></pre>

<p>or this:</p>

<pre><code>r'C:\Documents'
</code></pre>

<p>(unless or course you actually do want <code>\\</code>)</p>

<p>Edit:  I just noticed you also have an indentation problem:</p>

<pre><code>if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
</code></pre>

<p>should be:</p>

<pre><code>if os.system(zip_command) == 0:
    print 'Successful backup to', target
else:
</code></pre>

<p>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.</p>

python