'file'是python中的关键字吗? [英] Is 'file' a keyword in python?

查看:439
本文介绍了'file'是python中的关键字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

file是python中的关键字吗?

Is file a keyword in python?

我已经看到一些使用关键字file的代码很好,而其他代码则建议不要使用它,而我的编辑器则将其作为关键字进行颜色编码.

I've seen some code using the keyword file just fine, while others have suggested not to use it and my editor is color coding it as a keyword.

推荐答案

否,file是内置的,而不是关键字:

No, file is a builtin, not a keyword:

>>> import keyword
>>> keyword.iskeyword('file')
False
>>> import __builtin__
>>> hasattr(__builtin__, 'file')
True

它可以看作是open()的别名,但已从Python 3中删除,因为它是新的 io框架替换了它.从技术上讲,它是open()函数返回的对象的类型.

It can be seen as an alias for open(), but it has been removed from Python 3, as the new io framework replaced it. Technically, it is the type of object returned by the open() function.

这篇关于'file'是python中的关键字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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