Answers for "how to write and read a text file in python"

18

open text file in python

f=open("Diabetes.txt",'r')
f.read()
Posted by: Guest on April-25-2020
1

Write a Python program to read an entire text file

# 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')
Posted by: Guest on November-27-2020

Code answers related to "how to write and read a text file in python"

Python Answers by Framework

Browse Popular Code Answers by Language