string = "Deepika Padukone, Esha Gupta or Yami Gautam - Who's looks hotter and sexier? Vote! - It's ... Deepika Padukone, Esha Gupta or Yami Gautam…. Deepika Padukone, Esha Gupta or Yami Gautam ... Tag: Deepika Padukone, Esha Gupta, Kalki Koechlin, Rang De Basanti, Soha Ali Khan, Yami ... Amitabh Bachchan and Deepika Padukone to be seen in Shoojit Sircar's Piku ..."
fp = open("test.txt", "w+");
fp.write("%s" %string);
after running the above code I have got the following error.
File "encode_error.py", line 1
SyntaxError: Non-ASCII character '\xe2' in file encode_error.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
You have a U+2026 HORIZONTAL ELLIPSIS character in your string definition:
... Deepika Padukone, Esha Gupta or Yami Gautam…. ...
^
Python requires that you declare the source code encoding if you are to use any non-ASCII characters in your source.
Your options are to:
Declare the encoding, as specified in the linked PEP 263. It's is a comment that must be the first or second line of your source file.
What you set it to depends on your code editor. If you are saving files encoded as UTF-8, then the comment looks something like:
# coding: utf-8
but the format is flexible. You can spell it encoding
too, for example, and use =
instead of :
.
Replace the horizontal ellipsis with three dots, as used in the rest of the string
\xhh
escape sequences to represent encoded data. U+2026 encoded to UTF-8 is \xe2\x80\xa6
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With