SyntaxError: encoding problem: with BOM
sjmachin at lexicon.net
Thu Dec 25 14:21:03 CET 2008
On Dec 25, 11:36 pm, NoName <zaz... at gmail.com> wrote:
> On 25 дек, 03:35, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> > NoName schrieb:
> > > On 25 ÄÅË, 00:37, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> > >> NoName schrieb:
> > >>> i have 1.py in cp866 encoding:
> > >>> # -*- coding: cp866 -*-
> > >>> print ("ff")
> > >>> It's not work in Python 3.0
> > >>> Error:
> > >>> File "<decoding error>", line 1
> > >>> SyntaxError: encoding problem: with BOM
> > >>> what's wrong?
> > >> I can only guess, but just because you write the coding-header that
> > >> doesn't mean that the editor you use does actually *use* that encoding.
> > >> What I presume it does is to use utf-8, and write that stupid BOM
> > >> microsoft uses for denoting utf-8-content as first byte. Try using a
> > >> different editor, or alter it's settings to really use your desired
> > >> encoding.
> > >> Diez
> > > I used Far Manager editor. and it *really* used cp866
> > > I can print hex dump of source file.
> > > I don't want to use UTF-8 for py-file!
> > How about you show us the python file in question?
> > diez
> you can get it here http://slil.ru/26481345
NoName, Asking people to download a zip file from a website written in
a language and character set that they probably are not familiar with
is liable to make them rather nervous and not bother. It's not a good
way to ask for help. All you had to do was display the file contents
unambiguously, like this:
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open('11.py', 'rb').read()
b"# -*- coding: cp866 -*- \r\nprint('test')"
So, there's nothing very remarkable there ... a trailing space on the
end of the first line, the second line is not terminated by \r\n, no
non-ASCII characters in the file, ... nothing that might cause Python
to give you a syntax error.
... and it doesn't give a syntax error:
If you still maintain that you are getting the syntax error mentioned
in your first posting, please construct a file that causes the error
to happen on your machine (what type of machine? what OS are you
using?) and show (like I did above) firstly what is in the file and
secondly what happens when you run it. No hex editors, no websites, no
zip files, just plain Python like I did.
More information about the Python-list