Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to read a text line in Python?

1 Answer

0 votes
by (107k points)

For reading a text file in Python, you can use the below code:

# Open function to open the file "MyFile1.txt"  

# (same directory) in append mode and 

file1 = open("MyFile.txt","a") 

# store its reference in the variable file1  

# and "MyFile2.txt" in D:\Text in file2 

file2 = open(r"D:\Text\MyFile2.txt","w+") 

If you are looking for an online course to learn Python, I recommend this Python Training program by Intellipaat.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...