try中seek语句异常无法提交到except处理
try中seek方法异常无法提交到except处理,而是直接报错
try:
with open('test.txt') as fl:
print "in with file:", fl.read()
os.lseek(fl, -5, os.SEEK_SET)
except ValueError, e:
print "catch ValueError:", e
print "with:", fl.closedin with file: 123476868736db
Traceback (most recent call last):
File "test03.py", line 32, in <module>
os.lseek(fl, -5, os.SEEK_SET)
TypeError: an integer is required
这个和老师的实例不同啊,os.lseek()和file.seek()方法效果差不多,遇到的问题一样,我只是做下测试换用了os.lseek()方法
求解