Python File Read

 # File handling

# Read from file and display 


fp = None


try:

fp = open("iptfile.txt","r")

except IOError as e:

print("File opening error : ", e)

except:

print("unknown error")

else:

fdata = fp.read()

print(fdata)

finally:

if(fp):

fp.close()


"""

Sample output


Input file : iptfile.txt

Hello!!!

Welcome!!!

IT

CSE

EEE

ECE

Welcome!!!

Python


>python FileRead.py

Hello!!!

Welcome!!!

IT

CSE

EEE

ECE

Welcome!!!

Python

"""

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu