file.close()

try:
filename = raw_input('enter file name:')
fobj = open(filename, 'r')
for eachline in fobj:
print eachline, fobj.close() # Here to ask what to close files, close files, the fobj object is not a failure, how can you continue to read for cycle
except IOError, e:
print 'file open error:', e

Started by Eli at January 01, 2017 - 4:05 PM

  1. # -*- coding: utf-8 -*-
  2. def foo(filename):
  3. try:
  4. fobj = open(filename.decode('utf8'), 'r')
  5. for eachline in fobj:
  6. print eachline,
  7. fobj.close()
  8. except IOError, e:
  9. print 'file open error:', e

  10. foo('E:\books\ through Soybean Milk 4 rumors.Txt')
Oh, no problem, is the book the indentation problem.

Posted by Eli at January 14, 2017 - 3:51 PM