read text file in python

Create file named readfile.py

#!/usr/bin/python

import os
try:
    f = open("/home/directory/public_html/public/load.txt", "r")
    print(f.read())
    f.close()
    f.flush()
except IOError as (errno,strerror):
    print "I/O error({0}): {1}".format(errno, strerror)

run python file

$ python readfile.py


Leave a Reply