“从__future__导入大括号”代码在哪里?

时间:2022-04-13 22:57:12

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__.py and looked. surprisingly, I found nothing there that handle importing braces module.

因此,由于python是开源的,我打开了C:\Python27\Lib\__future__。py而且看。令人惊讶的是,我在那里找不到任何可以处理导入大括号模块的东西。

so, my question is, where is the code that handle this? what happen when I run that command?

我的问题是,处理这个的代码在哪里?当我运行这个命令时会发生什么?

1 个解决方案

#1


62  

The code is in 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;
  }

#1


62  

The code is in 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;
  }