File handling in python

months.py

months = open( “months.txt”, “w”)

months.write(“Jan\nFeb\nMar\nApr\nMay\nJun\nJul
\nAug\nSept\nOct\nNov\nDec”)

months.close()

fMonths=open(“months.txt”)

mon=fMonths.read()

while mon != “” :

       print(mon)

      mon = fMonths.read(1)

      print

Output

fileread

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.