How to enter arabic text in Python code?

my project should identify the mood, both positive and negative (mood analysis) in Arabic, for this task I used NLTK and python, when I entered tweets in Arabic, an error occurs

>>> pos_tweets = [(' أساند كل عون أمن شريف', 'positive'),
              ('ما أحلى الثورة التونسية', 'positive'),
              ('أجمل طفل في العالم', 'positive'),
              ('الشعب يحرس', 'positive'),
              ('ثورة شعبنا هي ثورة الكـــرامة وثـــورة الأحــــرار', 'positive')]
Unsupported characters in input

How can I solve this problem?

+5
source share
2 answers

Your problem arose from the IDLE shell. AFAIK IDLE will not accept UTF-8 input interactively.

I suggest you use alternative (and better) shells like DreamPie or Pythonwin .

+3
source

, , UTF-8 python. , , unicode script :

#! /usr/local/bin/python  -*- coding: UTF-8 -*-

pos_tweets = [(u' أساند كل عون أمن شريف', 'positive'), 
(u'ما أحلى الثورة التونسية', 'positive'), 
(u'أجمل طفل في العالم', 'positive'), 
(u'الشعب يحرس', 'positive'), 
(u'ثورة شعبنا هي ثورة الكـــرامة وثـــورة الأحــــرار', 'positive')] 

for i in pos_tweets:
  print i[0], i[1]
+3

All Articles