2

I'm working on a sentiment analysis program, it was working properly on a windows (python 3.4) but when I switched to a mac os (python 2.7) it gave me this error when i ran it:

SyntaxError: Non-ASCII character '\xc2' in file ./twitter.py on line 31, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

line 31 is where i try to remove the URLS from the tweets:

#removing urls(http:..)
twt = re.sub(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))', '', t)
Yasser Attia
  • 21
  • 1
  • 3
  • 1
    Have you tried declaring an encoding in `./twitter.py`, as described at https://www.python.org/dev/peps/pep-0263/ ? Sticking `# coding=utf-8` at the start of the file is usually enough. – phihag Mar 05 '19 at 07:33
  • In an addition to@phihag's comment, you will also need to add the `re.UNICODE` flag to your `re.sub` call. – snakecharmerb Mar 05 '19 at 07:37

0 Answers0