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 (108k 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.

Related questions

0 votes
2 answers
0 votes
1 answer
asked Mar 2, 2021 in Web Technology by dhanush (13.1k points)

Browse Categories

...