hello i want to print a Arabic text file in python3, and this is my code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# encoding: utf-8
#Read from the input file
input_file = open('triggertest.txt', 'r+')
for line in input_file:
print (line)
But i got this error:
Traceback (most recent call last):
File "try.py", line 6, in <module>
for line in input_file:
File "/Users/emansaad/anaconda/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 0: ordinal not in range(128)
when trying this solution:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# encoding: utf-8
#Read from the input file
input_file = open('triggertest.txt', 'r+',encoding='utf-8')
for line in input_file:
print (line)
I got this error:
Traceback (most recent call last):
File "try.py", line 7, in <module>
print (line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
triggertest.txt:
مرحبا
مرحباً بك
السلام عليكم
وعليكم السلام
ماهو سعر الايفون٧؟
يأتي بسعتين ٣٢ قيقا ب ٢٤٩٩ ريال و ١٢٨ قيقا ٢٨٩٩ ريال
when run locale
:
LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
when run locale charmap
:
US-ASCII