"TypeError: Can't convert 'int' object to str implicitly" Trying to rename files in python3
<p>I wrote the following function to rename a series of JPGs.  They come off the scanner as a sequential number, however I need to know what the front and back of each document is (in JPG form).  How I chose to do this is make one end in A, and one end in B.  For example:</p>

<ul>
<li>00001.jpg becomes 00001B.jpg</li>
<li>00002.jpg becomes 00001A.jpg</li>
<li>00003.jpg becomes 00002B.jpg</li>
<li>00004.jpg becomes 00002A.jpg</li>
</ul>

<p>This is because the scanner has a peculiar behavior, where the back is scanned before the front of each document.</p>

<p>I wrote the following function to handle this:</p>

<pre><code>def make_page_denotation(rename_directory, extension, rename_files):
    for filename in glob(rename_files):
        sequential_number = int(filename[-9:-4])
        if sequential_number &amp; 1 == True:
            os.rename(filename, filename.replace(str(sequential_number), str(sequential_number) + "B"))

        if sequential_number &amp; 1 == False:
            os.rename(filename, filename.replace(int(sequential_number), int(sequential_number) - 1))
            os.rename(filename, filename.replace(str(sequential_number), str(sequential_number) + "A"))
</code></pre>

<p>However, I am getting the following error:</p>

<pre><code>&gt; Traceback (most recent call last):
  File "imageqa.py", line 311, in &lt;module&gt;
    imageqa_misc.make_page_denotation(rename_directory, extension, rename_files)
  File "/home/mylan/workspace/Working/Image-QA/imageqa_misc.py", line 68, in make_page_denotation
    os.rename(filename, filename.replace(int(sequential_number), int(sequential_number) - 1))
TypeError: Can't convert 'int' object to str implicitly
</code></pre>

<p>I can't figure out, for the life of me why this is happening.  I'm still new to Python and programming in general, and am writing a series of scripts to help me out in everyday life to "dive right in" so any help would be greatly appreciated!  The odd test (first block) works perfectly on its own, so I'm not sure how I messed up the second block.</p>
