+ -
当前位置:首页 → 问答吧 → 请教一下

请教一下

时间:2010-12-12

来源:互联网

请问20-21行中,输入什么才能引起错误,退出循环呢?

  1. # Opening and writing to a file.

  2. import sys


  3. # open file
  4. try:
  5.    file = open( "clients.dat", "w" )  # open file in write mode
  6. except IOError, message:              # file open failed
  7.    print >> sys.stderr, "File could not be opened:", message
  8.    sys.exit( 1 )

  9. print "Enter the account, name and balance."
  10. print "Enter end-of-file to end input."

  11. while 1:

  12.    try:
  13.       accountLine = raw_input( "? " )   # get account entry
  14.    except EOFError:
  15.       break                             # user entered EOF
  16.    else:
  17.       print >> file, accountLine        # write entry to file
  18.       
  19. file.close()
复制代码

作者: eeeee159963   发布时间: 2010-12-12

EOFError:end of file,file is ended.
即当文件输入结束时,跳出循环。

作者: vividvivion   发布时间: 2010-12-12