
32
|
Python Pocket Reference
Attributes (all read-only)
file.closed
True
if file has been closed
file.mode
Mode string (e.g., 'r') passed to open function
file.name
String name of corresponding external file
Notes
• Some file-open modes (e.g., 'r+') allow a file to be both
input and output, and others (e.g.,
'rb') specify binary-
mode transfer to suppress line-end marker conversions.
See
open in the section “Built-in Functions,” later in this
book.
• File-transfer operations occur at the current file position,
but
seek method calls reposition the file for random
access.
• File transfers can be made unbuffered: see
open in the sec-
tion “Built-in Functions,” later in this book, and the
-u
command-line flag in the section “Command-Line
Options,” earlier in this book.
Other Common Types
As of Python 2.4, explicit Booleans, sets, and a numeric deci-
mal type are also available.
Boolean
The Boolean type, named bool, provides two predefined con-
stants, named
True and False (available since Version 2.3).
For most purposes, these constants can be treated as though
they were pre-assigned to integers 1 and 0, respectively (e.g.,
True + 3 yields 4). However, the bool type is a subclass of the
integer type,
int, and customizes it to print instances differ-
ently (
True prints as “True”, not “1”).