Is 'file' a keyword in python?

孤人 提交于 2019-11-26 20:51:12

问题


Is file a keyword in python?

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.


回答1:


No, file is a builtin, not a keyword:

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

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.



来源:https://stackoverflow.com/questions/24942358/is-file-a-keyword-in-python

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