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.
File Object Attribute | Description |
---|---|
file.closed | 1 if file is closed, 0 otherwise |
file.mode | access mode with which file was opened |
file.name | name of file |
file.softspace | 0 if space explicitly required with print, 1 otherwise; rarely used by the programmer—generally for internal use only |