将版权符号放入 Python 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/221376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 19:40:30  来源:igfitidea点击:

Putting Copyright Symbol into a Python File

pythonencoding

提问by Charles Anderson

I need to include a copyright statement at the top of every Python source file I produce:

我需要在我生成的每个 Python 源文件的顶部包含版权声明:

#   Copyright: ? 2008 etc.

However, when I then run such a file I get this message:

但是,当我然后运行这样的文件时,我收到以下消息:

SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.htmlfor details.

语法错误:第 3 行文件 MyFile.py 中的非 ASCII 字符“\xa9”,但未声明编码;有关详细信息,请参阅http://www.python.org/peps/pep-0263.html

Apparently Python isn't happy about the copyright symbol because it assumes the source file is all in ASCII. Either I need to make my first line be:

显然 Python 对版权符号不满意,因为它假设源文件都是 ASCII 格式的。要么我需要让我的第一行是:

# -*- coding: iso-8859-1 -*-

to tell Python I'm using Latin encoding, or I can change the copyright statement to:

告诉 Python 我正在使用拉丁语编码,或者我可以将版权声明更改为:

#   Copyright: \xa9 2008 etc.

which just possibly doesn't have the same legal standing.

这可能不具有相同的法律地位。

Is there a more elegant solution?

有没有更优雅的解决方案?

回答by S.Lott

The copyright symbol in ASCII is spelled (c)or "Copyright".

ASCII 中的版权符号拼写为(c)Copyright”。

See circular 61, Copyright Registration for Computer Programs.

参见第 61 号通告,计算机程序的版权注册

While it's true that the legal formalism (see Circular 1, Copyright Basics) is

虽然法律形式主义(见通告 1,版权基础)确实是

The symbol ? (the letter C in a circle), or the word “Copyright,” or the abbreviation “Copr.”; and...

符号 ? (圆圈中的字母 C),或“Copyright”一词,或缩写“Copr.”;和...

And it's also true that

这也是事实

To guarantee protection for a copyrighted work in all UCC member countries, the notice must consist of the symbol ? (the word “Copyright” or the abbreviation is not acceptable)

为保证在所有 UCC 成员国保护受版权保护的作品,通知必须包含符号 ? (“版权”一词或缩写是不可接受的)

You can dig through circular 3and 38a.

您可以挖掘循环338a

This has, however, already been tested in court. It isn't an interesting issue. If you do a search for "(c) acceptable for c-in-a-circle", you'll find that lawyers all agree that (c) is an acceptable substitute. See Perle and Williams. See Scott on Information Technology Law.

然而,这已经在法庭上进行了测试。这不是一个有趣的问题。如果您搜索“(c) 可接受 c-in-a-circle”,您会发现律师都同意 (c) 是可接受的替代品。见珀尔和威廉姆斯。参见 Scott 关于信息技术法。

回答by rjmunro

Contrary to the accepted answer, AFAIK, (c) is not an officially recognized alternative to the copyright symbol, although I'm not sure it's been tested in court.

与公认的答案相反,AFAIK,(c) 不是版权符号的官方认可替代品,尽管我不确定它是否已在法庭上进行过测试。

However, ? is just an abreviation of the word Copyright. Saying "Copyright 2008 Robert Munro" is identical to saying "? 2008 Robert Munro"

然而, ?只是版权一词的缩写。说“Copyright 2008 Robert Munro”等同于说“? 2008 Robert Munro”

Your "Copyright: ? 2008 etc." Expands to "Copyright: Copyright 2008 etc."

您的“版权:?2008 等” 扩展为“版权:Copyright 2008 等”。

Wikipedia's page seems to agree with me http://en.wikipedia.org/wiki/Copyright_symbol

维基百科的页面似乎同意我的看法http://en.wikipedia.org/wiki/Copyright_symbol

In the United States, the copyright notice consists of three elements: 1. the ? symbol, orthe word "Copyright" or abbreviation "Copr."; ...

在美国,版权声明由三个要素组成: 1. ? 符号,“版权”一词或缩写“Copr.”;...

回答by sergio

Put this line at first:

首先放这一行:

# -*- coding: utf-8 -*-

回答by A. L. Flanagan

For Python 2, the "right" thing to do is to specify the encoding, or never use non-ASCII characters. Specifying the encoding makes it simpler on the compiler and on humans. Sorry, but Python originally specified ASCII as the default, back in the Dark Ages.

对于 Python 2,“正确”的做法是指定编码,或者永远不要使用非 ASCII 字符。指定编码使编译器和人类更简单。抱歉,Python 最初在黑暗时代将 ASCII 指定为默认值。

For Python 3, UTF-8 is the default encoding, so you should be fine. In that case I would recommend not specifying the encoding if you use the default.

对于 Python 3,UTF-8 是默认编码,所以你应该没问题。在这种情况下,如果您使用默认值,我建议不要指定编码。

Whether a language allows/requires an encoding specification or not, in the age of Unicode this is an issue we need to keep in mind for every "text" file.

无论语言是否允许/需要编码规范,在 Unicode 时代,这是我们需要为每个“文本”文件牢记的问题。

回答by Alexander Kojevnikov

You can always revert to good old (c)

你总是可以回到美好的过去 (c)

回答by bortzmeyer

Waiting for Python 3k, where the default encoding of the source will be UTF-8?

等待Python 3k,其中源的默认编码将是 UTF-8?