try:
filename = "haiku.txt"
reval = "SUCCESS"
fptr = open(filename,"r")
if(not isinstance(fptr,file)):
print "\nCan not open ",filename,"\n"
reval = "FAIL"
else:
print "The value of fptr: ",fptr,"\n"
print "Ready to close the file."
fptr.close()
except IOError:
print "\nFile can not be opened\n"
def CharReadWrite(fin,fout):
while(1):
c = fin.readline()
if c == "":
break
else:
print c
fout.writelines(c)
try:
filename1 = "outhaiku.txt"
filename2 = "haiku.txt"
reval = "SUCCESS"
fptr1 = open(filename1,"w")
fptr2 = open(filename2,"r")
if(not isinstance(fptr1,file)):
print "\nCan not open ",filename1,"\n"
reval = "FAIL"
elif(not isinstance(fptr1,file)):
print "\nCan not open ",filename2,"\n"
reval = "FAIL"
else:
CharReadWrite(fptr2,fptr1)
fptr1.close()
fptr2.close()
except IOError:
print "\nFile can not be opened\n"
def LineReadWrite(fin,fout):
while(1):
c = fin.readline()
if c == "":
break
else:
print c
fout.writelines(c)
try:
filename1 = "outhaiku.txt"
filename2 = "haiku.txt"
reval = "SUCCESS"
fptr1 = open(filename1,"w")
fptr2 = open(filename2,"r")
if(not isinstance(fptr1,file)):
print "\nCan not open ",filename1,"\n"
reval = "FAIL"
elif(not isinstance(fptr1,file)):
print "\nCan not open ",filename2,"\n"
reval = "FAIL"
else:
LineReadWrite(fptr2,fptr1)
fptr1.close()
fptr2.close()
except IOError:
print "\nFile can not be opened\n"
def BlockReadWrite(fin,fout):
while(1):
c = fin.readline()
if c == "":
break
else:
print c
fout.writelines(c)
def ErrorMsg(str1):
print "Cannot open: ",str1,"\n"
return FAIL
try:
filename1 = "outhaiku.txt"
filename2 = "haiku.txt"
reval = "SUCCESS"
fptr1 = open(filename1,"w")
fptr2 = open(filename2,"r")
if(not isinstance(fptr1,file)):
print "\nCan not open ",filename1,"\n"
reval = ErrorMsg(filename1)
elif(not isinstance(fptr1,file)):
print "\nCan not open ",filename2,"\n"
reval = ErrorMsg(filename2)
else:
BlockReadWrite(fptr2,fptr1)
fptr1.close()
fptr2.close()
except IOError:
print "\nFile can not be opened\n"