Where is the “from __future__ import braces” code?

橙三吉。 提交于 2019-12-31 10:07:20

问题


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.

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


回答1:


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;
  }


来源:https://stackoverflow.com/questions/21125228/where-is-the-from-future-import-braces-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!