Python “从 __future__ 导入大括号”代码在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21125228/
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
Where is the "from __future__ import braces" code?
提问by Elisha
I was wondering what is exactly the code that executed on the command:
我想知道在命令上执行的代码到底是什么:
>>> from __future__ import braces
SyntaxError: not a chance
so, since python is open-sourced I opened C:\Python27\Lib\__future__.pyand looked.
surprisingly, I found nothing there that handle importing bracesmodule.
所以,由于python是开源的,我打开C:\Python27\Lib\__future__.py并查看。令人惊讶的是,我在那里没有发现任何处理导入braces模块的内容。
so, my question is, where is the code that handle this? what happen when I run that command?
所以,我的问题是,处理这个的代码在哪里?当我运行该命令时会发生什么?
采纳答案by Peter de Rivaz
The code is in future.c:
代码在future.c 中:
future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
...
else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
"not a chance");
PyErr_SyntaxLocation(filename, s->lineno);
return 0;
}

