try:
if(fp):
print "infile = ", fp
print "0"
except IOError:
print "1"
try:
fp = open("students.dat", "w")
if(fp):
print "infile = ", fp
print "0"
except IOError:
print "1"
fp = open("students.dat", "w")
print "Writing to the file"
print "==================="
print "Enter class name: ",
data = raw_input()
fp.write(data)
fp.write("\n")
print "Enter number of students: ",
data = raw_input()
fp.write(data)
fp.close()
fp = open("students.dat", "w")
print "Writing to the file"
print "==================="
print "Enter class name: ",
data = raw_input()
fp.write(data)
fp.write("\n")
print "Enter number of students: ",
data = raw_input()
fp.write(data)
fp.close()
fp = open("students.dat", "r")
print "Reading from the file"
print "====================="
lines = fp.readlines()
for line in lines:
print line
fp.close()
fp = open("students.dat", "w")
print "Writing to the file"
print "==================="
print "Enter class name: ",
data = raw_input()
fp.write(data)
fp.write("\n")
print "Enter number of students: ",
data = raw_input()
fp.write(data)
fp.close()
fp = open("students.dat", "r")
print "Reading from the file"
print "====================="
lines = fp.readlines()
for line in lines:
print line
fp.close()
fp = open("students.dat", "w")
print "Writing to the file"
print "==================="
print "Enter class name: ",
data = raw_input()
fp.write(data)
fp.write("\n")
print "Enter number of students: ",
data = raw_input()
fp.write(data)
fp.close()
fp = open("students.dat", "r")
print "Reading from the file"
print "====================="
while(fp.readline()):
print fp.readline()