The file Object Attributes in Python 3
Once a file is opened and you have one file object, you can get various information
related to that file.
Here
is a list of all the attributes related to a file object-
|
Attribute
|
Description
|
|
file.closed
|
Returns true if file is closed, false
otherwise.
|
|
file.mode
|
Returns access mode with which file was
opened.
|
|
file.name
|
Returns name of the file.
|
Note: softspace attribute is not supported in Python
3.x
Example
|
#!/usr/bin/python3
# Open
a file
fo =
open("foo.txt", "wb")
print
("Name of the file: ", fo.name)
print
("Closed or not : ", fo.closed)
print
("Opening mode : ", fo.mode)
fo.close()
|
This produces the following result-
|
Name of
the file: foo.txt
Closed
or not : False
Opening
mode : wb
|