Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'file' a keyword in python?

Tags:

python

keyword

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.

like image 438
user3388884 Avatar asked Jul 24 '14 19:07

user3388884


People also ask

What are the Python keywords?

Python keywords are special reserved words that have specific meanings and purposes and can't be used for anything but those specific purposes. These keywords are always available—you'll never have to import them into your code. Python keywords are different from Python's built-in functions and types.

What is a file in Python?

A file is some information or data which stays in the computer storage devices. You already know about different kinds of file , like your music files, video files, text files. Python gives you easy ways to manipulate these files. Generally we divide files in two categories, text file and binary file.

Which of these is not a keyword in Python?

1 Answer. The correct answer to the question “Which of the following is not a Keyword in Python” is option (a). Val. As Val is not a correct keyword, in Python and all others are keywords.


1 Answers

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.

like image 119
Martijn Pieters Avatar answered Oct 03 '22 22:10

Martijn Pieters