TypeError: sequence item 0 expected str instance, bytes found
<p>I am doing python challenge but when in mission 6 I met some problems:</p>

<pre><code>comments = []
comments.append(file_zip.getinfo('%s.txt'%name).comment)
print(''.join(comments))
</code></pre>

<p>but this give me the error</p>

<p>TypeError: sequence item 0: expected str instance, bytes found</p>

<p>I looked for the answer, and have a try like this:</p>

<pre><code>print(b''.join(comments))
</code></pre>

<p>it works.</p>

<pre><code>    b'***************************************************************\n****************************************************************\n**                                                    **\n**   OO    OO    XX    YYYY    GG    GG  EEEEEE NN      NN  **\n**    OO    OO  XXXXXX   YYYYYY   GG
    GG   EEEEEE  NN    NN   **\n**   OO    OO XXX  XXX YYY   YY  GG GG     EE       NN  NN    **\n**    OOOOOOOO XX    XX YY        GGG       EEEEE     NNNN     **\n**   OOOOOOOO XX    XX YY        GGG       EEEEE      NN      **\n**   OO    OO XXX  XXX YYY   YY  GG GG     EE         NN      **\n**
 OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE     NN      **\n**   OO      OO         XX       YYYY    GG    GG  EEEEEE     NN  
</code></pre>

<p>I think it regards <code>'/n'</code> as a char and print it,but I don't want that, how can I make it work?</p>

<p>The issue is that <code>file_zip.getinfo('%s.txt'%name).comment</code> apparently returns a <code>bytes</code> object(s). When you try and join on an <code>str</code>, namely <code>''.join(..)</code> you get the error:</p>

<pre><code>''.join([b'hello', b'\n', b'world'])    
TypeError: sequence item 0: expected str instance, bytes found
</code></pre>

<p>Joining on <code>b''</code> is a viable alternative but, as you note, it doesn't escape special characters like <code>'\n'</code>; that's expected behavior for <code>bytes</code> instances. </p>

<p>You can either <code>decode</code> the string after it has been <code>join</code>ed on <code>b''</code>:</p>

<pre><code>print(b''.join(comments).decode())
</code></pre>

<p>Or, <code>decode</code> every element of <code>comments</code> with <code>map</code> and <code>join</code> on an empty string <code>''</code> as you originally attempted:</p>

<pre><code>print(''.join(map(bytes.decode, comments)))
</code></pre>

python string python-3.x