Computer Science
When a file is opened for output in append mode, what happens when
(i) the mentioned file does not exist
(ii) the mentioned file does exist.
Answer
When a file is opened for output in append mode ("a" mode) in Python, the behaviour differs depending on whether the mentioned file already exists or not:
(i) If the mentioned file does not exist — If the file specified in the open() function does not exist, Python will create a new file with the given name. The file will be opened for writing, and any data written to it will be appended to the end of the file.
(ii) If the mentioned file does exist — If the file specified in the open() function already exists, the data in the file is retained and new data being written will be appended to the end of the file.
Related Questions
When do you think text files should be preferred over binary files ?
Write a statement in Python to perform the following operations :
(a) To open a text file "BOOK.TXT" in read mode
(b) To open a text file "BOOK.TXT" in write mode
How many file objects would you need to create to manage the following situations ? Explain.
(i) to process three files sequentially
(ii) to merge two sorted files into a third file.
Is csv file different from a text file ? Why/why not ?