Avatar ·

مشكلة الترميز عند الكتابة إلى ملف: UnicodeEncodeError: 'charmap' codec can't encode character '\u039a'

📁 بايثون

مطلوب إجراء تحليل vk وفقًا للمعايير المحددة وكتابة النتيجة في ملف باستخدام Python 3.5.

search_result = api.users.search(sort=sort_index, sex=sex_index, age_to=age_index, offset=offset_index, count=count_index, country=country) result = open('result.txt', 'w') index = 0 while index != (count_index - offset_index): result.write(str(search_result[index + 1])) result.write('\n') index += 1 result.close()

أحصل على خطأ:

Traceback (most recent call last): File "E:\\...\\vk_script.py", line 19, in <module> result.write(str(search_result[index + 1])) File "C:\\Python35\\lib\\encodings\\cp1251.py", line 19, in encode return self._encode(input, self.errors)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u039a' in position 0: character maps to <undefined>