filmov
tv
Python file handling methods with different modes to read write & append data in text & binary mode

Показать описание
We can read write or append data by using File handling objects by using methods in Python. We can use read more to read only data from file, the file must be existing. In write mode data can be written to file or new file can be crated. In write mode if file is not existing then new file is created. In append mode data is added at the end of the file, so existing data is not overwritten. In append mode if file is not there then new file is created.
In exclusive mode we can write data like write mode but we can use new file only, previously existing files can’t be used for any modification in x or exclusive mode.
By using read() method we can collect full data or part of the data from the file.
We can read by readline() method. Using for loop we can browse through all the lines and display data.
In append mode we can add data at the end of the file , one new file is created if the file is not available.
In write mode data is over written so previous data is lost. A new file is crated if the file is not available.
In exclusive mode only new file can be crated and no existing file is allowed to open.
In binary mode we can create a copy of any image or binary file. By default file handling mode is text only , by using rb mode we can read the file in binary mode. Similarly by using wb we can write the file in binary mode. We can copy one image by creating a new file by using read and write in binary mode.
In exclusive mode we can write data like write mode but we can use new file only, previously existing files can’t be used for any modification in x or exclusive mode.
By using read() method we can collect full data or part of the data from the file.
We can read by readline() method. Using for loop we can browse through all the lines and display data.
In append mode we can add data at the end of the file , one new file is created if the file is not available.
In write mode data is over written so previous data is lost. A new file is crated if the file is not available.
In exclusive mode only new file can be crated and no existing file is allowed to open.
In binary mode we can create a copy of any image or binary file. By default file handling mode is text only , by using rb mode we can read the file in binary mode. Similarly by using wb we can write the file in binary mode. We can copy one image by creating a new file by using read and write in binary mode.