- Get link
- X
- Other Apps
Text File I/O in Python
Hello programmers!
In this tutorial, I will teach you the basic text file I/O(input/output) using python. So let's get started.
Sometimes, it is not enough to only display the data on the console. The data to be displayed may be very large, and only a limited amount of data can be displayed on the console since the memory is volatile, it is impossible to recover the programmatically generated data again and again.
The file handling plays an important role when the data needs to be stored permanently in the file. A file is a named location on a disk to store related information. We can access the stored information (non-volatile) after the program termination.
Open a file
file = open("test.txt")
In the above code, we have opened a file in the current directory.
file = open("D:/Python/test.txt")
In the above code, we have opened a file in another place.
Writing in a file
file = open("test.txt", "w")
file.write("This line has been written using Python")
file.close()
In the above code, we have written a line in a text file using python. We are first opening a file in writing mode. Then we are writing a line in the file. Then we closing the file.
Congratulations! Now you have learned the basic file I/O using python. If you have any confusion then comment below.
Happy Coding :)
python, python files, files in python, learn python, python tutorial, python for beginners, python file io, python tutorial in hindi, write file in python, python 3 ,python tutorial for beginners, python (programming language), file handling in python,python file i/o, file handling in python 3, python open file, learn python in hindi, python write file, file handling in python pycharm, file handling in python examples, python file handling, python read file, python file read, files, python file tutorial
Comments
Post a Comment