title: python can encode to utf-8 but can't decode
body: <p>The Code Below Can Encode A String To Utf-8 :</p>
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  str = 'ورود'
  print(str.encode('utf-8'))
  </code></pre>
  <p>That Prints:</p>
  <pre><code>b'\xd9\x88\xd8\xb1\xd9\x88\xd8\xaf'
  </code></pre>
  <p>But I can't Decode This String With This Code :</p>
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  str = b'\xd9\x88\xd8\xb1\xd9\x88\xd8\xaf'
  print(str.decode('utf-8'))
  </code></pre>
  <p>The error is:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\test.py&quot;, line 5, in &lt;module&gt;
      print(str.decode('utf-8'))
  AttributeError: 'str' object has no attribute 'decode'
  </code></pre>
  <p>Please Help Me ...</p>
  <h3>Edit</h3>
  <p>From the answers switched to a byte string:</p>
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  str = b'\xd9\x88\xd8\xb1\xd9\x88\xd8\xaf'
  print(str.decode('utf-8'))
  </code></pre>
  <p>Now the error is:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\test.py&quot;, line 5, in &lt;module&gt;
      print(str.decode('utf-8'))
    File &quot;C:\Python34\lib\encodings\cp437.py&quot;, line 19, in encode
      return codecs.charmap_encode(input,self.errors,encoding_map)[0]
  UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character maps to &lt;undefined&gt;
  </code></pre>