Python string assignment error occurs on second loop, but not first
<p>The first run-through of the while loop goes fine:</p>

<pre><code>hour_count = list('00/')
hours = 0

while hours &lt; 24:                    #loop while hours &lt; 24

    hour_count[1] = hours            #&lt;- error occurs on this line
    hour_count = ''.join(hour_count) #convert to string
    ...
    hours += 1
</code></pre>

<p>However, upon the second loop, it gives a TypeError: 'str' object does not support item assignment. The purpose is to set a file path.</p>

<p>You changed the type;</p>

<pre><code># hour_count at this point is an array
hour_count[1] = hours

# The result of join is a string object
hour_count = ''.join(hour_count)
</code></pre>

<p>Next time through <code>hour_count</code> is a string and you can't do "string[1] = ..."</p>

python python-3.x typeerror