Is 'file' a keyword in python?

后端 未结 1 1356
无人及你
无人及你 2020-12-01 11:50

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

相关标签:
1条回答
  • 2020-12-01 12:14

    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.

    0 讨论(0)
提交回复
热议问题