#!/usr/bin/env pythonimport oswhile True: print "Please Input File's Name:", fileName = raw_input() if os.path.exists(fileName): break else: print "File %s Don't Exist.Please Input Thr Truth Name."newFile = open(fileName,'r')for lines in newFile: print lines,newFile.close()
第11题 #!/usr/bin/env pythonimport oswhile True: print "Please Input File's Name:", fileName = raw_input() if os.path.exists(fileName): break else: print "File %s Don't Exist.Please Input Thr Truth Name."newFile = open(fileName,'r')for lines in newFile: lines.rstrip() print linesnewFile.close() 第12题#!/sur/bin/env pythonimport oslineEnd = os.linesepprint "A:Creat A New File"print "B:Read A File That's Had Existed."chooseLetter = raw_input(">")if chooseLetter == 'A': while True: print"Please Input The File's Name:", fileName = raw_input() if os.path.exists(fileName): print "File %s Has Existed.Please Input Truth Name." else: break textForFile = [] print "Please Input Any Text,'.' To Quit." while True: chs = raw_input() if chs == '.': break else: textForFile.append(chs) newFile = open(fileName,'w') newFile.writelines(['%s%s' % (X,lineEnd) for X in textForFile]) newFile.close() print "Done." exit()elif chooseLetter == 'B': while True: print "Please Input The Name Of File:", existFile = raw_input() if os.path.exists(existFile): break else: print "Can't Find File %s,Please Input Truth Name."%existFile fileForRead = open(existFile,'r') for lines in fileForRead: print lines, fileForRead.close() print"Done." exit()else: print"Done." exit()