Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Files, Modules and Packag...
  5. Files
  6. File Object attributes

File Object attributes

File Object

  • Once a file is successfully opened, a file object is returned. Using this file object, one can easily access different types of information related to the file
  • This information can be obtained by reading values of specific attribute of the file

Example

fp = open("new_file","w")
s = "Welcome All!!"
fp.write(s)
print("Check file is closed ?:",fp.closed)
fp.close()
print("And Now, file is closed:",fp.closed)
print("Mode in which file is open:",fp.mode)
print("Name of the file:",fp.name)

Output

Check file is closed ?: False
And Now, file is closed: True
Mode in which file is open: w
Name of the file: new_file

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments