Groky
0
Q:

Write a Python program to read an entire text file

file1 = open("MyFile.txt","w+") 

file1.readline()

fil1.write("string")

file1.close()
7
# Program to read entire file
import os
PATH = "H:\\py_learning\\interviewsprep"
os.chdir(PATH)
def file_read(fname,mode='r+'):
    try:
        with open(fname) as txt:
            print(txt.read())
            print('>>>>>>>>>>>>>>>')
    except FileNotFoundError:
        print("check file existance in current working directory i.e : ",os.getcwd())
        print('provide file existance path to PATH variable')
    finally:
        pass
file_read('file1.txt')
0

New to Communities?

Join the community