Python 语法错误:没有机会

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17811855/
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-08-19 09:14:44  来源:igfitidea点击:

Syntax Error: Not a Chance

pythonsyntax-errorcurly-braces

提问by Anurag-Sharma

I tried executed the following code in the python IDLE

我尝试在 python IDLE 中执行以下代码

from __future__ import braces 

And I got the following error:

我收到以下错误:

SyntaxError: not a chance

What does the above error mean?

上面的错误是什么意思?

采纳答案by Martijn Pieters

You have found an easter egg in Python. It is a joke.

您已经在 Python 中找到了一个复活节彩蛋。这是一个笑话。

It means that delimiting blocks by braces instead of indentation will never be implemented.

这意味着永远不会实现用大括号而不是缩进来分隔块。

Normally, imports from the special __future__moduleenable features that are backwards-incompatible, such as the print()function, or true division.

通常,从特殊__future__模块导入会启用向后不兼容的print()功能,例如函数或真正的除法。

So the line from __future__ import bracesis taken to mean you want to enable the 'create blocks with braces' feature, and the exception tells you your chances of that everhappening are nil.

因此,线from __future__ import braces被认为是指你要启用该功能“用括号来创建块”,异常告诉您那的机会不断发生的零。

You can add that to the long list of in-jokes included in Python, just like import __hello__, import thisand import antigravity. The Python developers have a well-developed sense of humour!

您可以将其添加到 Python 中包含的长长的笑话列表中,就像import __hello__import this和 一样import antigravity。Python 开发者的幽默感非常发达!

回答by zhangyangyu

The __future__module is normally used to provide features from future versions of Python.

__future__模块通常用于提供 Python 未来版本的功能。

This is an easter egg that summarizes its developers' feelings on this issue.

这是一个彩蛋,总结了开发者对这个问题的感受。

There are several more:

还有几个:

import thiswill display the zen of Python.

import this将展示 Python 之禅。

import __hello__will display Hello World....

import __hello__将显示Hello World....

In Python 2.7 and 3.0, import antigravitywill open the browser to a comic!

在 Python 2.7 和 3.0 中,import antigravity浏览器会打开一个漫画!