1

I have an array of text, I want to write it to a .txt file from right to left since it is in Arabic or Kurdish. How can I do that using python?

Method to write to a file:

with open(current_extracted_text_output_path, 'w', encoding='utf-8') as text_file:
    for line in extracted_lines:
        print(line)
        text_file.write(line + '\n')

Output:

enter image description here

3
  • Does the MacOS text editor support rending arabic text RTL? Maybe a right-to-left mark helps. Commented Jan 5, 2024 at 15:18
  • I have used PyCharm and VS Code, the problem still exists. Commented Jan 5, 2024 at 15:21
  • Your code appears correct and should be sufficient to write the file. I am not sure about PyCham, but VSCode will render Arabic script text correctly, in logical order, but isn't able to right align or wrap Arabic script text, so far from ideal for reading text files, but adequate for displaying shorter strings and for programming. Commented Jan 5, 2024 at 22:17

1 Answer 1

1

Did you try this Lib:

import codecs
with codecs.open('final.txt', 'w', encoding='utf-8') as text_file:
        for line in array_of_text:

            text_file.write('\u200F' + line + '\n')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.