5 Python File Modes to Deal with Big data

Python file modes, the purpose is to open, read, write the files. There are occasions you need to deal with data, which is present in the files. You need to give correct file-modes to handle the files in Python.

File Open Modes in Python
Python file open modes

File Open Modes in Python.

filename = input('Enter a filename : ')
f1 = open(filename, 'mode')

Python File mode w 

To open the file for writing, you need w mode. The beauty of this is If the file does not exist, it creates one. This mode's purpose is to write the file. If you try to read, you will get an error.

Python File mode w+

To Open the file for Reading and Writing, you need w+ mode. For instance, you used w+, you have tried to read the file - after writing, it displays blank. The reason is after writing cursor position will point at the end of the file.

Python File mode a

It appends the records at the end of the existing file. The file must exist to use this mode.

Python File mode r

To open a file in read-only mode. If the file does not exist, it throws an error.

Pythom File mode r+

Both read and write. When you write the data to the file, it writes at the end. Now, the cursor is at the end of the file. When you perform read, it gives blank.

In the 'r+' mode, if the file does not exist, and if you try to read, which gives an error.



Popular Posts

How to Fix Python Syntax Errors Quickly

Python 'getsizeof' Command the Real Purpose

7 AWS Interview Questions asked in Infosys, TCS

Hyperledger Fabric: 20 Real Interview Questions

How to Decode TLV Quickly

QlikView Server vs Publisher Top Differences Really Useful to Your Project

AWS Vs Azure Load Balancers Top Insights

Top 10 SCALA Quiz Questions for Programmers

Python Syntax Errors Cheat Sheet

How to Use the ps Command in Linux