PEP 8: Byte Order Mark (BOM) vs coding cookie

T

twyk

PEP 8 says ...

Files using ASCII (or UTF-8, for Python 3.0) should not have a coding
cookie.

What about a BOM (Byte Order Mark)? Per Wikipedia ...

http://en.wikipedia.org/wiki/Byte-order_mark#endnote_UTF-8)

'In UTF-8, this is not really a "byte order" mark. It identifies the
text as UTF-8 but doesn't say anything about the byte order, because
UTF-8 does not have byte order issues.'

So is it good style to omit the BOM in UTF-8 for Python 3.0?
 
M

Marc 'BlackJack' Rintsch

So is it good style to omit the BOM in UTF-8 for Python 3.0?

I'd say yes because it is unnecessary with UTF-8 and it messes up the she-
bang line of scripts.

Ciao,
Marc 'BlackJack' Rintsch
 
T

Terry Reedy

twyk said:
PEP 8 says ...

Files using ASCII (or UTF-8, for Python 3.0) should not have a coding
cookie.
What about a BOM (Byte Order Mark)? Per Wikipedia ...

http://en.wikipedia.org/wiki/Byte-order_mark#endnote_UTF-8)

'In UTF-8, this is not really a "byte order" mark. It identifies the
text as UTF-8 but doesn't say anything about the byte order, because
UTF-8 does not have byte order issues.'

So is it good style to omit the BOM in UTF-8 for Python 3.0?

According to Unicode manual, yes.

http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf

The endian order entry for UTF-8 in Table 2-4 is marked N/A because
UTF-8 code units are 8 bits in size, and the usual machine issues of
endian order for larger code units do not apply. The serialized order of
the bytes must not depart from the order defined by the UTF-
8 encoding form. Use of a BOM is neither required nor recommended for
UTF-8, but may be encountered in contexts where UTF-8 data is converted
from other encoding forms that use a BOM or where the BOM is used as a
UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8,
Specials, for more information.

Since Ascii files *are*, by intentional design, UTF-8 files, and since
Python assumes Ascii/UTF-8 as the default, in the absence of a coding
cookie, it does not need the signature.
 

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

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,119
Latest member
NoeliaIrby

Latest Threads

Top