Computer Science
How is file open() function different from close() function?
Python File Handling
10 Likes
Answer
open() function | close() function |
---|---|
The open() function is used to open a file. | The close() function is used to close a file object. |
It creates a file object, which allows to perform various operations on the file, such as reading from it, writing to it, or appending data to it. | When we're done working with a file, we should always close it using the close() function to free up system resources and prevent data loss. |
The syntax is : file_objectname = open("filename", "mode") | The syntax is : file.close() |
Answered By
6 Likes
Related Questions
What is the difference between "w" and "a" modes ?
What is the significance of a file-object ?
Write statements to open a binary file C:\Myfiles\Text1.txt in read and write mode by specifying file path in two different formats.
Which of the following Python modules is imported to store and retrieve objects using the process of serialization and deserialization ?
- csv
- binary
- math
- pickle