makedirs() gives AttributeError: 'int' object has no attribute 'rfind'
Question: I'm trying to create a program that saves a backup by creating a directory for
a zip file: This is an exercise from _A byte of python_ (I'm going to give the
full example so that you guys can see where he's going.) The example code is:

    
    
        #! /usr/bin/env python3
        import os
        import time
    
    
        # 1. The files and directories to be backed up are specified in a list.
        source = ['~/Desktop/python']
    
        # 2. The backup must be stored in a main backup directory
        target_dir = '~/Dropbox/Backup/' # Remember to change this to what you'll be using
    
        # 3. The files are backed up into a zip file.
        # 4. the name of the zip archive is the current date and time
        target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') +'.zip'
        now = time.strftime('%H%M%S')
    
        # Create the subdirectory if it isn't already there.
        if not os.path.exists(today):
            os.mkdir(today) # make directory
            print('Successfully created directory', today)
    
        # The name of the zip file 
        target = today + os.sep + now + '.zip'
    
        # 5. We use the zip command to put the files in a zip archive
        zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))
        print(zip_command)
        # Run the backup
        if os.system(zip_command) == 0:
            print('Successful backup to', target)
        else:
            print('Backup FAILED')
    

This pulls up the error:

    
    
        Traceback (most recent call last):
           File "backup_ver2.py", line 23, in <module>
            os.mkdir(today) # make directory
         TypeError: mkdir: illegal type for path parameter
    

My solution:

    
    
        import os
        import time
    
        today = 14052016 # I set today as a string to solve a previous issue.
    
        .....
        # Create the subdirectory if it isn't already there.
        if not os.path.exists(today):
            os.makedirs(today, exist_ok=True) # make directory
            print('Successfully created directory', today)
    

Which gives the error:

    
    
        Traceback (most recent call last):
          File "backup_ver2a.py", line 23, in <module>
            os.makedirs(today, exist_ok=True) # make directory
          File "/usr/lib/python3.4/os.py", line 222, in makedirs
            head, tail = path.split(name)
          File "/usr/lib/python3.4/posixpath.py", line 103, in split
             i = p.rfind(sep) + 1
        AttributeError: 'int' object has no attribute 'rfind' 
    

This traceback has referenced lines in the module so now I know I'm in
trouble. Is it possible that the variable "today" is still at the heart of
both of these errors? Is there a better way to define today so as not to pull
so many errors or is there a better way to check and create a subdirectory? If
you guys notice more errors in his example, please don't correct them. I'm
sure I'll find them soon. :) Thanks for any help.

Notes: I'm running ubuntu 14.04 LTS and use python 3


Answer: Agreeing with @gdlmx, both errors resulting from your variable "today" which
is an int and not a string and thus, you need to simple make the change to
that variable from an int to a string by putting it in a quote, like the
following line of code:

    
    
    today = "14052016"
    

Once this is done the errors you're getting should be fade away.

