title: Python 3 print() function with Farsi/Arabic characters
body: <p>I simplified my code for better understanding.
  here is the problem :</p>
  
  <p><strong>case 1:</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  text = "چرا کار نمیکنی؟" # also using u"...." results the same
  print(text)
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to &lt;undefined&gt;
  </code></pre>
  
  <p><strong>case 2:</strong></p>
  
  <pre><code>text = "چرا کار نمیکنی؟".encode("utf-8") 
  print(text)
  </code></pre>
  
  <p>there is no output.</p>
  
  <p><strong><a href="https://stackoverflow.com/a/22543438/5284370">case</a> 3:</strong></p>
  
  <pre><code>import sys
  
  text = "چرا کار نمیکنی؟".encode("utf-8")
  sys.stdout.buffer.write(text)
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>چرا کار نمیکنی؟
  </code></pre>
  
  <hr>
  
  <p>I know that case 3 works somehow , but I want to use other functions like print() , write(str()) , ....</p>
  
  <p>I also read the documentation of python 3 regarding to Unicode <a href="https://docs.python.org/3.3/howto/unicode.html" rel="noreferrer">here</a>.</p>
  
  <p>and also read dozens of Q&amp;A in stackoverflow.</p>
  
  <p>and <a href="http://www.spencegreen.com/2008/12/19/python-arabic-unicode/" rel="noreferrer">here</a> is a long article explaining the problem and answer for python 2.X</p>
  
  <p>the simple question is:</p>
  
  <p><strong>how to print non-ASCII characters like Farsi or Arabic using python print() function?</strong></p>
  
  <p>update 1 :
  as it is suggested from many guys that the problem is concerned with the terminal I tested the case :</p>
  
  <p><strong>case 4 :</strong></p>
  
  <pre><code>text = "چرا کار نمیکنی؟" .encode("utf-8")# also using u"...." results the same
  print(text)
  </code></pre>
  
  <p>terminal :</p>
  
  <pre><code>python persian_encoding.py &gt; test.txt
  </code></pre>
  
  <p>test.txt :</p>
  
  <pre><code>b'\xda\x86\xd8\xb1\xd8\xa7 \xda\xa9\xd8\xa7\xd8\xb1 \xd9\x86\xd9\x85\xdb\x8c\xda\xa9\xd9\x86\xdb\x8c\xd8\x9f'
  </code></pre>
  
  <p><strong>very important update:</strong></p>
  
  <p>after a while playing around with this issue, finally I found another workaround to make cmd.exe do the job (without needing third party softwares like ConEmu or ...):</p>
  
  <p>a little explanation first:</p>
  
  <p>our main problem does not concern Python. it's a problem with the Command Prompt character set in Windows(for complete explanation check out Arman's Answer)
  so ... if you change the character set of Windows Command Prompt to UTF-8 instead of default ascii , then the Command Prompt will be able to interact with UTF-8 characters(like Farsi or Arabic) this solution does not guarantee good representation of characters(as they will be printed out like little squares), but it's a good solution if you want to have file I/O in python with UTF-8 characters.</p>
  
  <p><strong>Steps:</strong></p>
  
  <p>before starting python from command line , type:</p>
  
  <pre><code>chcp 65001
  </code></pre>
  
  <p>now run your python code as always.</p>
  
  <pre><code>python testcode.py
  </code></pre>
  
  <p>result in case 1: </p>
  
  <pre><code>?????? ??? ??????
  </code></pre>
  
  <p>it runs without errors.</p>
  
  <p>screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/hJvto.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hJvto.png" alt="enter image description here"></a></p>
  
  <p>for more information about how to set 65001 as the default character set check <a href="https://stackoverflow.com/a/18439832/5284370">this</a> out.</p>