How to import Text file in Python
![how to import text file in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-import-text-file-in-python-1024x576.jpg)
In Python, you can import modules, but not text files. If you want to obtain data from a text file, you can use the Python file operations. Python provides inbuilt functions for creating, writing, and reading files.
Assume we have the following text file:
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-2020-12-13-131145.jpg)
To open the file, we can use the built-in file function open()
. The open()
function returns a file object, which has a read()
method for reading the content of the file:
f = open("Students.txt") print(f.read())
Output:
Name Age Grade ABEL 20 A BINDU 21 A CHRISTY 20 A YOUSUF 21 A KRISHNA 20 A
Subscribe
Login
Please login to comment
0 Discussion