9.4. File Built-in Attributes

File objects also have data attributes in addition to its methods. These attributes hold auxiliary data related to the file object they belong to, such as the file naFme (file.name), the mode with which the file was opened (file.mode), whether the file is closed (file.closed), and a flag indicating whether an additional space character needs to be displayed before successive data items when using the print statement (file.softspace).Table 9.4 lists these attributes along with a brief description of each.

Table 9.4. Attributes for File Objects
File Object AttributeDescription
file.closed1 if file is closed, 0 otherwise
file.modeaccess mode with which file was opened
file.namename of file
file.softspace0 if space explicitly ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.