“从 __future__ 导入大括号"在哪里?代码? [英] Where is the "from __future__ import braces" code?

查看:44
本文介绍了“从 __future__ 导入大括号"在哪里?代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在命令上执行的代码到底是什么:

<预><代码>>>>从 __future__ 导入大括号语法错误:没有机会

所以,由于 python 是开源的,我打开了 C:\Python27\Lib\__future__.py 并查看.令人惊讶的是,我在那里没有发现任何处理导入 braces 模块的内容.

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

解决方案

代码在future.c:

future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)...否则如果(strcmp(功能,大括号")== 0){PyErr_SetString(PyExc_SyntaxError,没有机会");PyErr_SyntaxLocation(文件名,s->lineno);返回0;}

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?

解决方案

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

这篇关于“从 __future__ 导入大括号"在哪里?代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆