On 5/20/18 7:59 AM, bellcanada...@gmail.com wrote: > On Saturday, 19 May 2018 19:03:09 UTC-4, Chris Angelico wrote: >> On Sun, May 20, 2018 at 8:58 AM, <bellcanada...@gmail.com> wrote: >>> On Thursday, 29 January 2009 12:09:29 UTC-5, Anjanesh Lekshminarayanan >>> wrote: >>>>> It does auto-detect it as cp1252- look at the files in the traceback and >>>>> you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong >>>>> encoding, try opening it as utf-8 or latin1 and see if that fixes it. >>>> Thanks a lot ! utf-8 and latin1 were accepted ! >>> hello i am having same issue..i believe the code is written in python 2 and >>> i am running python 3.6..i tried at the interpreter..f = >>> open(filename, encoding="utf-8" and also latin-1..but then when i run my >>> file i still get the error...also my line is at 7414..how do you find this >>> line??...is it better to try to run the file .py in python 2??..thnxz >> You're responding to something from 2009. >> >> Your file is apparently not encoded the way you think it is. You'll >> have to figure out what it ACTUALLY is. >> >> ChrisA > > hello Chris > thank you for the reply, but how exactly am i supposed to find oout what is > the correct encodeing??
Basically, you need to know it from some other source to be totally certain. This is part of the 'disaster' of 8 bit code pages. There are a few guesses that can be done that often get you close. utf-8, IF it validates is almost always what the file is (unless it is just ASCII, where you generally never even notice the issue). There are programs that will look at some heuristics in the file and try to guess. Another option is to open the file in a text editor which will be more forgiving and show the bad character as an error symbol, and see if you can recognize what 'language' (human) the user seems to have been using, and guess the character encoding from that (or just remove the bad characters if they are just in comments/unimportant strings.) -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list