SyntaxError: encoding problem: with BOM

N

NoName

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?
 
D

Diez B. Roggisch

NoName said:
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
 
N

NoName

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!
 
D

Diez B. Roggisch

NoName said:
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
 
J

John Machin


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:

C:\downloads>\python30\python
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.
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:

C:\downloads>\python30\python 11.py
test

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.
 
N

NoName

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.

sorry:)

Now i know where problem.
But i dont know how to solve it.

Error
----
C:\Documents and Settings\Ra\òÁÂÏÞÉÊ ÓÔÏÌ>11.py
File "<decoding error>", line 1
SyntaxError: encoding problem: with BOM

No error
----
C:\Documents and Settings\Ra\òÁÂÏÞÉÊ ÓÔÏÌ>python 11.py
test

Error when russian symbols in full path to py-script.
Is it Python bug? or i need to modify some registry keys?

OS: WinXP SP3 Russian.
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
 
N

NoName

It's a bug, please report it. I though we fixed all Windows path bugs
for 3.0 but apparently one slipped through.

Christian

It is too difficult for me. please help me=)
 
G

Gabriel Genellina

Error
----
C:\Documents and Settings\Ra\Рабочий Ñтол>11.py
File "<decoding error>", line 1
SyntaxError: encoding problem: with BOM

No error
----
C:\Documents and Settings\Ra\Рабочий Ñтол>python 11.py
test

Error when russian symbols in full path to py-script.
Is it Python bug? or i need to modify some registry keys?

Yes, it's a bug. The encoding declaration may be anything, ascii, even an
inexistent codec will trigger the bug. Any non-ascii character in the
script name or path provokes then a SyntaxError when the script is
executed directly.
As a workaround, avoid using any Russian characters in directory names or
script file names, or invoke them always using "python xxx.py", not
directly.
OS: WinXP SP3 Russian.
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32

My tests were on WinXP SP3 Spanish.
See http://bugs.python.org/issue4747
 
N

NoName

Error when russian symbols in full path to py-script.
Is it Python bug? or i need to modify some registry keys?

Yes, it's a bug. The encoding declaration may be anything, ascii, even an
inexistent codec will trigger the bug. Any non-ascii character in the
script name or path provokes then a SyntaxError when the script is
executed directly.
As a workaround, avoid using any Russian characters in directory names or
script file names, or invoke them always using "python xxx.py", not
directly.
OS: WinXP SP3 Russian.
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32

My tests were on WinXP SP3 Spanish.
Seehttp://bugs.python.org/issue4747


Gabriel Genellina, thanks for bug report =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top