Program to check a file's status in file handling in Python
# Program to check a file's status in file Handling...
# main method
def main():
# Opening the file
fileObject = open("file.dat","rb")
# Printing object's status
print("Name of the File : ",fileObject.name)
print("Closed or Not : ",fileObject.closed)
print("Opening Mode : ",fileObject.mode)
fileObject.close()
print("")
print("Closed or Not : ",fileObject.closed)
if __name__=="__main__":main()
Program to check a file's status in file handling in Python
File : File.dat
Output:
Explanation:
In the above code, we have opened a file using a file object named fileObject. Using this we have checked for the object's name, status, and mode.
need an explanation for this answer? contact us directly to get an explanation for this answer