How to print Persian word in vscode terminal Python

Viewed 276

I'm using vscode and when I try to print this

print('شیرینی پزی')

the output of terminal is

ی‌ز‌پ ی‌ن‌ی‌ر‌ی‌ش

what should I do

1 Answers

Note: The following solution is for displaying the RTL texts. Don't use the output in your code. It's just for printing in wherever RTL texts are messed up.

First install arabic_reshaper and bidi

pip install arabic-reshaper
pip install python-bidi

Then, use the following function:

import arabic_reshaper
from bidi.algorithm import get_display

def convert(text):
    reshaped_text = arabic_reshaper.reshape(text)
    converted = get_display(reshaped_text)
    return converted
print(convert('شیرینی پزی'))

The output:

>>> شیرینی پزی
Related