Back
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+")
# 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